Add php files

This commit is contained in:
2025-05-12 15:44:39 +00:00
parent c951760058
commit 82d5804ac4
9534 changed files with 2638137 additions and 0 deletions

95
include/EditView/EditView.php Executable file
View File

@@ -0,0 +1,95 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
class EditView {
/**
* smarty object
* @var object
*/
var $ss;
/**
* location of template to use
* @var string
*/
var $template;
/**
* Module to use
* @var string
*/
var $module;
/**
*
* @param string $module module to use
* @param string $template template of the form to retreive
*/
function EditView($module, $template) {
$this->module = $module;
$this->template = $template;
$this->ss = new Sugar_Smarty();
}
/**
* Processes / setups the template
* assigns all things to the template like mod_srings and app_strings
*
*/
function process() {
global $current_language, $app_strings, $sugar_version, $sugar_config, $timedate, $theme;;
$module_strings = return_module_language($current_language, $this->module);
$this->ss->assign('SUGAR_VERSION', $sugar_version);
$this->ss->assign('JS_CUSTOM_VERSION', $sugar_config['js_custom_version']);
$this->ss->assign('THEME', $theme);
$this->ss->assign('APP', $app_strings);
$this->ss->assign('MOD', $module_strings);
}
/**
* Displays the template
*
* @return string HTML of parsed template
*/
function display() {
return $this->ss->fetch($this->template);
}
}
?>

719
include/EditView/EditView2.php Executable file
View File

@@ -0,0 +1,719 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/TemplateHandler/TemplateHandler.php');
require_once('include/EditView/SugarVCR.php');
class EditView
{
var $th;
var $tpl;
var $notes;
var $id;
var $metadataFile;
var $headerTpl;
var $footerTpl;
var $returnAction;
var $returnModule;
var $returnId;
var $isDuplicate;
var $focus;
var $module;
var $fieldDefs;
var $sectionPanels;
var $view = 'EditView';
var $formatFields = true;
var $showDetailData = true;
var $showVCRControl = true;
var $showSectionPanelsTitles = true;
var $quickSearchCode;
var $ss;
var $offset = 0;
var $populateBean = true;
var $moduleTitleKey;
var $viewObject = null;
var $formName = '';
/**
* EditView constructor
* This is the EditView constructor responsible for processing the new
* Meta-Data framework
*
* @param $module String value of module this Edit view is for
* @param $focus An empty sugarbean object of module
* @param $id The record id to retrieve and populate data for
* @param $metadataFile String value of file location to use in overriding default metadata file
* @param tpl String value of file location to use in overriding default Smarty template
* @param createFocus bool value to tell whether to create a new bean if we do not have one with an id, this is used from ConvertLead
*
*/
function setup($module, $focus = null, $metadataFile = null, $tpl = 'include/EditView/EditView.tpl', $createFocus = true)
{
$this->th = new TemplateHandler();
$this->th->ss =& $this->ss;
$this->tpl = $tpl;
$this->module = $module;
$this->focus = $focus;
//this logic checks if the focus has an id and if it does not then it will create a new instance of the focus bean
//but in convert lead we do not want to create a new instance and do not want to populate id.
if($createFocus)
{
$this->createFocus();
}
if(empty($GLOBALS['sugar_config']['showDetailData'])) {
$this->showDetailData = false;
}
$this->metadataFile = $metadataFile;
if(!empty($sugar_config['disable_vcr'])) {
$this->showVCRControl = $sugar_config['disable_vcr'];
}
if(!empty($this->metadataFile) && file_exists($this->metadataFile)){
include($this->metadataFile);
}else {
//If file doesn't exist we create a best guess
if(!file_exists("modules/$this->module/metadata/editviewdefs.php") &&
file_exists("modules/$this->module/EditView.html")) {
require_once('include/SugarFields/Parsers/EditViewMetaParser.php');
global $dictionary;
$htmlFile = "modules/" . $this->module . "/EditView.html";
$parser = new EditViewMetaParser();
if(!file_exists('modules/'.$this->module.'/metadata')) {
sugar_mkdir('modules/'.$this->module.'/metadata');
}
$fp = sugar_fopen('modules/'.$this->module.'/metadata/editviewdefs.php', 'w');
fwrite($fp, $parser->parse($htmlFile, $dictionary[$focus->object_name]['fields'], $this->module));
fclose($fp);
}
//Flag an error... we couldn't create the best guess meta-data file
if(!file_exists("modules/$this->module/metadata/editviewdefs.php")) {
global $app_strings;
$error = str_replace("[file]", "modules/$this->module/metadata/editviewdefs.php", $app_strings['ERR_CANNOT_CREATE_METADATA_FILE']);
$GLOBALS['log']->fatal($error);
echo $error;
die();
}
require_once("modules/$this->module/metadata/editviewdefs.php");
}
$this->defs = $viewdefs[$this->module][$this->view];
$this->isDuplicate = isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true' && $this->focus->aclAccess('edit');
}
function createFocus()
{
global $beanList, $beanFiles;
if(empty($beanList[$this->module]))return;
if(!$this->focus ){
$bean = $beanList[$this->module];
require_once($beanFiles[$bean]);
$obj = new $bean();
$this->focus = $obj;
}
//If there is no idea, assume we are creating a new instance
//and call the fill_in_additional_detail_fields where initialization
//code has been moved to
if(empty($this->focus->id)) {
global $current_user;
$this->focus->fill_in_additional_detail_fields();
$this->focus->assigned_user_id = $current_user->id;
}
}
function populateBean()
{
if(!empty($_REQUEST['record']) && $this->populateBean) {
global $beanList;
$bean = $beanList[$this->module];
$obj = new $bean();
$this->focus = $obj->retrieve($_REQUEST['record']);
} else {
$GLOBALS['log']->debug("Unable to populate bean, no record parameter found");
}
}
/**
* enableFormatting
* This method is used to manually turn on/off the field formatting
* @param $format boolean value to turn on/off field formatting
*/
function enableFormatting(
$format = true
)
{
$this->formatFields = $format;
}
function requiredFirst()
{
$panels = array('required'=>array());
$reqCol = -1;
$reqRow = 0;
foreach($this->defs['panels'] as $key=>$p){
foreach($p as $row=>$rowDef) {
foreach($rowDef as $col => $colDef) {
$field = (is_array($p[$row][$col])) ? $p[$row][$col]['name'] : $p[$row][$col];
if((!empty($this->focus->field_defs[$field])
&& !empty($this->focus->field_defs[$field]['required']))
|| ( !empty($p[$row][$col]['displayParams']['required'])
&& ( isset($this->focus->field_defs[$field]) ? $this->focus->field_defs[$field]['required'] !== false : false ) ) ) {
$reqCol++;
if($reqCol == $this->defs['templateMeta']['maxColumns']) {
$reqCol = -1;
$reqRow++;
}
$panels['required'][$reqRow][$reqCol] = $p[$row][$col];
}else{
$panels[$key][$row][$col] = $p[$row][$col];
}
} //foreach
} //foreach
} //foreach
$this->defs['panels'] = $panels;
}
function render()
{
$totalWidth = 0;
foreach($this->defs['templateMeta']['widths'] as $col => $def) {
foreach($def as $k => $value) $totalWidth += $value;
}
// calculate widths
foreach($this->defs['templateMeta']['widths'] as $col => $def) {
foreach($def as $k => $value)
$this->defs['templateMeta']['widths'][$col][$k] = round($value / ($totalWidth / 100), 2);
}
$this->sectionPanels = array();
$this->sectionLabels = array();
if(!empty($this->defs['panels']) && count($this->defs['panels']) > 0) {
$keys = array_keys($this->defs['panels']);
if(is_numeric($keys[0])) {
$defaultPanel = $this->defs['panels'];
unset($this->defs['panels']); //blow away current value
$this->defs['panels'][''] = $defaultPanel;
}
}
if($this->view == 'EditView' && !empty($GLOBALS['sugar_config']['forms']['requireFirst'])){
$this->requiredFirst();
}
$maxColumns = isset($this->defs['templateMeta']['maxColumns']) ? $this->defs['templateMeta']['maxColumns'] : 2;
$panelCount = 0;
static $itemCount = 100; //Start the generated tab indexes at 100 so they don't step on custom ones.
/* loop all the panels */
foreach($this->defs['panels'] as $key=>$p)
{
$panel = array();
if(!is_array($this->defs['panels'][$key])) {
$this->sectionPanels[strtoupper($key)] = $p;
} else {
foreach($p as $row=>$rowDef) {
$columnsInRows = count($rowDef);
$columnsUsed = 0;
foreach($rowDef as $col => $colDef) {
$panel[$row][$col] = is_array($p[$row][$col]) ? array('field' => $p[$row][$col]) : array('field' => array('name'=>$p[$row][$col]));
$panel[$row][$col]['field']['tabindex'] = (isset($p[$row][$col]['tabindex']) && is_numeric($p[$row][$col]['tabindex'])) ? $p[$row][$col]['tabindex'] : $itemCount;
if($columnsInRows < $maxColumns) {
if($col == $columnsInRows - 1) {
$panel[$row][$col]['colspan'] = 2 * $maxColumns - ($columnsUsed + 1);
} else {
$panel[$row][$col]['colspan'] = floor(($maxColumns * 2 - $columnsInRows) / $columnsInRows);
$columnsUsed = $panel[$row][$col]['colspan'];
}
}
//Set address types to have colspan value of 2 if colspan is not already defined
if(isset($colDef['type']) && $colDef['type'] == 'address' && $this->view == 'EditView' && !isset($panel[$row][$col]['colspan'])) {
$panel[$row][$col]['colspan'] = 2;
}
$itemCount++;
} //foreach
} //foreach
// Panel alignment will be off if the panel doesn't have a row with the max columns
// It will not be aligned to the other panels so we add a filler row
$addFiller = true;
foreach($panel as $row) {
if(count($row) == $this->defs['templateMeta']['maxColumns']) {
$addFiller = false;
break;
}
}
if($addFiller) {
$filler = 0;
$rowCount = count($panel);
while($filler < $this->defs['templateMeta']['maxColumns']) {
$panel[$rowCount][$filler++] = array('field'=>array('name'=>''));
} //while
}
$this->sectionPanels[strtoupper($key)] = $panel;
}
$panelCount++;
} //foreach
}
function process(
$checkFormName = false,
$formName = ''
)
{
global $mod_strings, $sugar_config, $app_strings, $app_list_strings;
//the retrieve already did this work;
//$this->focus->fill_in_relationship_fields();
if(!$this->th->checkTemplate($this->module, $this->view, $checkFormName, $formName)){
$this->render();
}
if(isset($_REQUEST['offset'])) {
$this->offset = $_REQUEST['offset'] - 1;
} //if
if($this->showVCRControl) {
$this->th->ss->assign('PAGINATION', SugarVCR::menu($this->module, $this->offset, $this->focus->is_AuditEnabled(), ($this->view == 'EditView')));
} //if
if(isset($_REQUEST['return_module'])) $this->returnModule = $_REQUEST['return_module'];
if(isset($_REQUEST['return_action'])) $this->returnAction = $_REQUEST['return_action'];
if(isset($_REQUEST['return_id'])) $this->returnId = $_REQUEST['return_id'];
if(isset($_REQUEST['return_relationship'])) $this->returnRelationship = $_REQUEST['return_relationship'];
if(isset($_REQUEST['return_name'])) $this->returnName = $this->getValueFromRequest($_REQUEST, 'return_name' ) ;
// handle Create $module then Cancel
if (empty($this->returnId)) {
$this->returnAction = 'index';
}
$is_owner = $this->focus->isOwner($GLOBALS['current_user']->id);
$this->fieldDefs = array();
if($this->focus){
global $current_user;
/*if(empty($this->focus->assigned_user_id) ){
$this->focus->assigned_user_id = $current_user->id;
}*/
if(!empty($this->focus->assigned_user_id)) {
$this->focus->assigned_user_name = get_assigned_user_name($this->focus->assigned_user_id);
}
foreach($this->focus->toArray() as $name => $value) {
$valueFormatted = false;
//if($this->focus->field_defs[$name]['type']=='link')continue;
if (!empty($this->fieldDefs[$name]) && !empty($this->fieldDefs[$name]['value']))
$this->fieldDefs[$name] = array_merge($this->focus->field_defs[$name] , $this->fieldDefs[$name] ) ;
else
$this->fieldDefs[$name] = $this->focus->field_defs[$name];
foreach(array("formula", "default", "comments", "help") as $toEscape)
{
if (!empty($this->fieldDefs[$name][$toEscape])) {
$this->fieldDefs[$name][$toEscape] = htmlentities($this->fieldDefs[$name][$toEscape], ENT_QUOTES, 'UTF-8');
}
}
if(isset($this->fieldDefs[$name]['options']) && isset($app_list_strings[$this->fieldDefs[$name]['options']])) {
$this->fieldDefs[$name]['options'] = $app_list_strings[$this->fieldDefs[$name]['options']]; // fill in enums
} //if
if(isset($this->fieldDefs[$name]['function'])) {
$function = $this->fieldDefs[$name]['function'];
if(is_array($function) && isset($function['name'])){
$function = $this->fieldDefs[$name]['function']['name'];
}else{
$function = $this->fieldDefs[$name]['function'];
}
if(!empty($this->fieldDefs[$name]['function']['returns']) && $this->fieldDefs[$name]['function']['returns'] == 'html'){
if(!empty($this->fieldDefs[$name]['function']['include'])){
require_once($this->fieldDefs[$name]['function']['include']);
}
$value = $function($this->focus, $name, $value, $this->view);
$valueFormatted = true;
}else{
$this->fieldDefs[$name]['options'] = $function($this->focus, $name, $value, $this->view);
}
}
if(isset($this->fieldDefs[$name]['type']) && $this->fieldDefs[$name]['type'] == 'function' && isset($this->fieldDefs[$name]['function_name'])){
$value = $this->callFunction($this->fieldDefs[$name]);
$valueFormatted = true;
}
if(!$valueFormatted) {
// $this->focus->format_field($this->focus->field_defs[$name]);
$value = isset($this->focus->$name) ? $this->focus->$name : '';
}
if (empty($this->fieldDefs[$name]['value']))
{
$this->fieldDefs[$name]['value'] = $value;
}
//This code is used for QuickCreates that go to Full Form view
if($this->populateBean && empty($this->focus->id) && !isset($this->fieldDefs[$name]['function']) && isset($_REQUEST[$name])) {
$this->fieldDefs[$name]['value'] = $this->getValueFromRequest($_REQUEST, $name);
} //if
/*
* Populate any relate fields that are linked by a relationship to the calling module.
* Clicking the create button on a subpanel for example will populate three values in the $_REQUEST:
* 1. return_module => the name of the calling module
* 2. return_id => the id of the record in the calling module that the user was viewing and that should be associated with this new record
* 3. return_name => the display value of the return_id record - the value to show in any relate field in this EditView
* Only do if this fieldDef does not already have a value; if it does it will have been explicitly set, and that should overrule this less specific mechanism
*/
if (isset($this->returnModule) && isset($this->returnName) && empty($this->focus->id) && empty($this->fieldDefs['name']['value']) )
{
if ( ($this->focus->field_defs[$name]['type'] == 'relate') && isset($this->focus->field_defs[$name][ 'module' ]) && $this->focus->field_defs[$name][ 'module' ] == $this->returnModule )
{
if (isset( $this->fieldDefs[$name]['id_name'])
&& !empty($this->returnRelationship)
&& isset($this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship'])
&& ($this->returnRelationship == $this->focus->field_defs[$this->fieldDefs[$name]['id_name']]['relationship']))
{
$this->fieldDefs[$name]['value'] = $this->returnName ;
// set the hidden id field for this relate field to the correct value i.e., return_id
$this->fieldDefs[$this->fieldDefs[$name]['id_name']]['value'] = $this->returnId ;
}
}
}
} //foreach
} //if
if(isset($this->focus->additional_meta_fields)) {
$this->fieldDefs = array_merge($this->fieldDefs, $this->focus->additional_meta_fields);
}
if($this->isDuplicate) {
foreach($this->fieldDefs as $name=>$defs) {
if(!empty($defs['auto_increment'])) {
$this->fieldDefs[$name]['value'] = '';
}
}
}
}
/**
* display
* This method makes the Smarty variable assignments and then displays the
* generated view.
* @param $showTitle boolean value indicating whether or not to show a title on the resulting page
* @param $ajaxSave boolean value indicating whether or not the operation is an Ajax save request
* @return HTML display for view as String
*/
function display(
$showTitle = true,
$ajaxSave = false
)
{
global $mod_strings, $sugar_config, $app_strings, $app_list_strings, $theme, $current_user;
if(isset($this->defs['templateMeta']['javascript'])) {
if(is_array($this->defs['templateMeta']['javascript'])) {
$this->th->ss->assign('externalJSFile', 'modules/' . $this->module . '/metadata/editvewdefs.js');
} else {
$this->th->ss->assign('scriptBlocks', $this->defs['templateMeta']['javascript']);
}
}
$this->th->ss->assign('id', $this->fieldDefs['id']['value']);
$this->th->ss->assign('offset', $this->offset + 1);
$this->th->ss->assign('APP', $app_strings);
$this->th->ss->assign('MOD', $mod_strings);
$this->th->ss->assign('fields', $this->fieldDefs);
$this->th->ss->assign('sectionPanels', $this->sectionPanels);
$this->th->ss->assign('returnModule', $this->returnModule);
$this->th->ss->assign('returnAction', $this->returnAction);
$this->th->ss->assign('returnId', $this->returnId);
$this->th->ss->assign('isDuplicate', $this->isDuplicate);
$this->th->ss->assign('def', $this->defs);
$this->th->ss->assign('useTabs', isset($this->defs['templateMeta']['useTabs']) ? $this->defs['templateMeta']['useTabs'] : false);
$this->th->ss->assign('maxColumns', isset($this->defs['templateMeta']['maxColumns']) ? $this->defs['templateMeta']['maxColumns'] : 2);
$this->th->ss->assign('module', $this->module);
$this->th->ss->assign('headerTpl', isset($this->defs['templateMeta']['form']['headerTpl']) ? $this->defs['templateMeta']['form']['headerTpl'] : 'include/' . $this->view . '/header.tpl');
$this->th->ss->assign('footerTpl', isset($this->defs['templateMeta']['form']['footerTpl']) ? $this->defs['templateMeta']['form']['footerTpl'] : 'include/' . $this->view . '/footer.tpl');
$this->th->ss->assign('current_user', $current_user);
$this->th->ss->assign('bean', $this->focus);
$this->th->ss->assign('isAuditEnabled', $this->focus->is_AuditEnabled());
$this->th->ss->assign('gridline',$current_user->getPreference('gridline') == 'on' ? '1' : '0');
global $js_custom_version;
global $sugar_version;
$this->th->ss->assign('SUGAR_VERSION', $sugar_version);
$this->th->ss->assign('JS_CUSTOM_VERSION', $js_custom_version);
//this is used for multiple forms on one page
if ( !empty($this->formName) ) {
$form_id = $this->formName;
$form_name = $this->formName;
}
else {
$form_id = $this->view;
$form_name = $this->view;
}
if($ajaxSave && empty($this->formName)){
$form_id = 'form_'.$this->view .'_'.$this->module;
$form_name = $form_id;
$this->view = $form_name;
//$this->defs['templateMeta']['form']['buttons'] = array();
//$this->defs['templateMeta']['form']['buttons']['ajax_save'] = array('id' => 'AjaxSave', 'customCode'=>'<input type="button" class="button" value="Save" onclick="this.form.action.value=\'AjaxFormSave\';return saveForm(\''.$form_name.'\', \'multiedit_form_{$module}\', \'Saving {$module}...\');"/>');
}
$form_name = $form_name == "QuickCreate" ? "QuickCreate_{$this->module}" : $form_name;
$form_id = $form_id == "QuickCreate" ? "QuickCreate_{$this->module}" : $form_id;
if(isset($this->defs['templateMeta']['preForm'])) {
$this->th->ss->assign('preForm', $this->defs['templateMeta']['preForm']);
} //if
if(isset($this->defs['templateMeta']['form']['closeFormBeforeCustomButtons'])) {
$this->th->ss->assign('closeFormBeforeCustomButtons', $this->defs['templateMeta']['form']['closeFormBeforeCustomButtons']);
}
if(isset($this->defs['templateMeta']['form']['enctype'])) {
$this->th->ss->assign('enctype', 'enctype="'.$this->defs['templateMeta']['form']['enctype'].'"');
}
//for SugarFieldImage, we must set form enctype to "multipart/form-data"
foreach($this->fieldDefs as $field){
if(isset($field['type']) && $field['type'] == 'image'){
$this->th->ss->assign('enctype', 'enctype="multipart/form-data"');
break;
}
}
$this->th->ss->assign('showDetailData', $this->showDetailData);
$this->th->ss->assign('showSectionPanelsTitles', $this->showSectionPanelsTitles);
$this->th->ss->assign('form_id', $form_id);
$this->th->ss->assign('form_name', $form_name);
$this->th->ss->assign('set_focus_block', get_set_focus_js());
$this->th->ss->assign('form', isset($this->defs['templateMeta']['form']) ? $this->defs['templateMeta']['form'] : null);
$this->th->ss->assign('includes', isset($this->defs['templateMeta']['includes']) ? $this->defs['templateMeta']['includes'] : null);
$this->th->ss->assign('view', $this->view);
//Calculate time & date formatting (may need to calculate this depending on a setting)
global $timedate;
$this->th->ss->assign('CALENDAR_DATEFORMAT', $timedate->get_cal_date_format());
$this->th->ss->assign('USER_DATEFORMAT', $timedate->get_user_date_format());
$time_format = $timedate->get_user_time_format();
$this->th->ss->assign('TIME_FORMAT', $time_format);
$date_format = $timedate->get_cal_date_format();
$time_separator = ":";
if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) {
$time_separator = $match[1];
}
// Create Smarty variables for the Calendar picker widget
$t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
if(!isset($match[2]) || $match[2] == '') {
$this->th->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
} else {
$pm = $match[2] == "pm" ? "%P" : "%p";
$this->th->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
}
$this->th->ss->assign('TIME_SEPARATOR', $time_separator);
$seps = get_number_seperators();
$this->th->ss->assign('NUM_GRP_SEP', $seps[0]);
$this->th->ss->assign('DEC_SEP', $seps[1]);
if($this->view == 'EditView') {
$height = $current_user->getPreference('text_editor_height');
$width = $current_user->getPreference('text_editor_width');
$height = isset($height) ? $height : '300px';
$width = isset($width) ? $width : '95%';
$this->th->ss->assign('RICH_TEXT_EDITOR_HEIGHT', $height);
$this->th->ss->assign('RICH_TEXT_EDITOR_WIDTH', $width);
} else {
$this->th->ss->assign('RICH_TEXT_EDITOR_HEIGHT', '100px');
$this->th->ss->assign('RICH_TEXT_EDITOR_WIDTH', '95%');
}
$this->th->ss->assign('SHOW_VCR_CONTROL', $this->showVCRControl);
//$str='';
$str = $this->showTitle($showTitle);
//Use the output filter to trim the whitespace
$this->th->ss->load_filter('output', 'trimwhitespace');
$str .= $this->th->displayTemplate($this->module, $form_name, $this->tpl, $ajaxSave, $this->defs);
return $str;
}
function insertJavascript(
$javascript
)
{
$this->ss->assign('javascript', $javascript);
}
function callFunction(
$vardef
)
{
$can_execute = true;
$execute_function = array();
$execute_params = array();
if(!empty($vardef['function_class'])){
$execute_function[] = $vardef['function_class'];
$execute_function[] = $vardef['function_name'];
}else{
$execute_function = $vardef['function_name'];
}
foreach($vardef['function_params'] as $param ){
if (empty($vardef['function_params_source']) or $vardef['function_params_source']=='parent'){
if(empty($this->focus->$param)){
$can_execute = false;
}else{
$execute_params[] = $this->focus->$param;
}
}else if ($vardef['function_params_source']=='this'){
if(empty($this->focus->$param)){
$can_execute = false;
}else{
$execute_params[] = $this->focus->$param;
}
}else{
$can_execute = false;
}
}
$value = '';
if($can_execute){
if(!empty($vardef['function_require'])){
require_once($vardef['function_require']);
}
$value = call_user_func_array($execute_function, $execute_params);
}
return $value;
}
/**
* getValueFromRequest
* This is a helper method to extract a value from the request
* Array. We do some special processing for fields that start
* with 'date_' by checking to see if they also include time
* and meridiem values
*
* @param request The request Array
* @param name The field name to extract value for
* @return String value for given name
*/
function getValueFromRequest(
$request,
$name
)
{
//Special processing for date values (combine to one field)
if(preg_match('/^date_(.*)$/s', $name, $matches)) {
$d = $request[$name];
if(isset($request['time_' . $matches[1]])) {
$d .= ' ' . $request['time_' . $matches[1]];
if(isset($request[$matches[1] . '_meridiem'])) {
$d .= $request[$matches[1] . '_meridiem'];
}
} else {
if(isset($request['time_hour_' . $matches[1]]) &&
isset($request['time_minute_' . $matches[1]])) {
$d .= ' ' . $request['time_hour_' . $matches[1]] . ':' . $request['time_minute_' . $matches[1]];
}
if(isset($request['meridiem'])) {
$d .= $request['meridiem'];
}
}
return $d;
}
return $request[$name];
}
/**
* Allow Subviews to overwrite this method to show custom titles.
* Examples: Projects & Project Templates.
* params: $showTitle: boolean for backwards compatibility.
*/
public function showTitle(
$showTitle = false
)
{
global $mod_strings, $app_strings;
if (is_null($this->viewObject))
if (!empty($GLOBALS['current_view']))
$this->viewObject = $GLOBALS['current_view'];
else
$this->viewObject = new SugarView();
if ($showTitle)
return $this->viewObject->getModuleTitle();
return '';
}
}

View File

@@ -0,0 +1,76 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/EditView/EditView.php');
class QuickCreate extends EditView {
/**
* True if the create being populated via an AJAX call?
*/
var $viaAJAX = false;
function process() {
global $current_user, $timedate;
parent::process();
$this->ss->assign('ASSIGNED_USER_ID', $current_user->id);
$this->ss->assign('REQUEST', array_merge($_GET, $_POST));
$this->ss->assign('CALENDAR_LANG', "en");
$date_format = $timedate->get_cal_date_format();
$this->ss->assign('USER_DATEFORMAT', '('. $timedate->get_user_date_format().')');
$this->ss->assign('CALENDAR_DATEFORMAT', $date_format);
$time_format = $timedate->get_user_time_format();
$time_separator = ":";
if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) {
$time_separator = $match[1];
}
$t23 = strpos($time_format, '23') !== false ? '%H' : '%I';
if(!isset($match[2]) || $match[2] == '') {
$this->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M");
} else {
$pm = $match[2] == "pm" ? "%P" : "%p";
$this->ss->assign('CALENDAR_FORMAT', $date_format . ' ' . $t23 . $time_separator . "%M" . $pm);
}
}
}
?>

View File

@@ -0,0 +1,120 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
require_once('include/EditView/EditView2.php');
class SubpanelQuickCreate{
function SubpanelQuickCreate($module, $view='QuickCreate'){
// locate the best viewdefs to use: 1. custom/module/quickcreatedefs.php 2. module/quickcreatedefs.php 3. custom/module/editviewdefs.php 4. module/editviewdefs.php
$base = 'modules/' . $module . '/metadata/';
$source = 'custom/' . $base . strtolower($view) . 'defs.php';
if (!file_exists( $source))
{
$source = $base . strtolower($view) . 'defs.php';
if (!file_exists($source))
{
//if our view does not exist default to EditView
$view = 'EditView';
$source = 'custom/' . $base . 'editviewdefs.php';
if (!file_exists($source))
{
$source = $base . 'editviewdefs.php';
}
}
}
$this->ev = new EditView();
$this->ev->view = $view;
$this->ev->ss = new Sugar_Smarty();
//$_REQUEST['return_action'] = 'SubPanelViewer';
$this->ev->setup($module, null, $source);
$this->ev->defs['templateMeta']['form']['headerTpl'] = 'include/EditView/header.tpl';
$this->ev->defs['templateMeta']['form']['footerTpl'] = 'include/EditView/footer.tpl';
$this->ev->defs['templateMeta']['form']['buttons'] = array('SUBPANELSAVE', 'SUBPANELCANCEL', 'SUBPANELFULLFORM');
$defaultProcess = true;
$viewEditSource = 'modules/'.$module.'/views/view.edit.php';
if (file_exists('custom/'. $viewEditSource)) {
$viewEditSource = 'custom/'. $viewEditSource;
}
if(file_exists($viewEditSource)) {
include($viewEditSource);
$c = $module . 'ViewEdit';
if(class_exists($c)) {
$view = new $c;
if($view->useForSubpanel) {
$defaultProcess = false;
//Check if we shold use the module's QuickCreate.tpl file
if($view->useModuleQuickCreateTemplate && file_exists('modules/'.$module.'/tpls/QuickCreate.tpl')) {
$this->ev->defs['templateMeta']['form']['headerTpl'] = 'modules/'.$module.'/tpls/QuickCreate.tpl';
}
$view->ev = & $this->ev;
$view->ss = & $this->ev->ss;
$class = $GLOBALS['beanList'][$module];
if(!empty($GLOBALS['beanFiles'][$class])){
require_once($GLOBALS['beanFiles'][$class]);
$bean = new $class();
$view->bean = $bean;
}
$this->ev->formName = 'form_Subpanel'.$this->ev->view .'_'.$module;
$view->showTitle = false; // Do not show title since this is for subpanel
$view->display();
}
}
} //if
if($defaultProcess) {
$this->process($module);
}
}
function process($module){
$form_name = 'form_Subpanel'.$this->ev->view .'_'.$module;
$this->ev->formName = $form_name;
$this->ev->process(true, $form_name);
echo $this->ev->display(false, true);
}
}
?>

186
include/EditView/SugarVCR.php Executable file
View File

@@ -0,0 +1,186 @@
<?php
/*********************************************************************************
* SugarCRM is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
* technical reasons, the Appropriate Legal Notices must display the words
* "Powered by SugarCRM".
********************************************************************************/
/*
* Created on Jul 24, 2007
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
define('VCREND', '50');
define('VCRSTART', '10');
class SugarVCR{
/**
* records the query in the session for later retrieval
*/
function store($module, $query){
$_SESSION[$module .'2_QUERY'] = $query;
}
/**
* This function retrieves a query from the session
*/
function retrieve($module){
return (!empty($_SESSION[$module .'2_QUERY']) ? $_SESSION[$module .'2_QUERY'] : '');
}
/**
* return the start, prev, next, end
*/
function play($module, $offset){
//given some global offset try to determine if we have this
//in our array.
$ids = array();
if(!empty($_SESSION[$module.'QUERY_ARRAY']))
$ids = $_SESSION[$module.'QUERY_ARRAY'];
if(empty($ids[$offset]) || empty($ids[$offset+1]) || empty($ids[$offset-1]))
$ids = SugarVCR::record($module, $offset);
$menu = array();
if(!empty($ids[$offset])){
//return the control given this id
$menu['PREV'] = ($offset > 1) ? $ids[$offset-1] : '';
$menu['CURRENT'] = $ids[$offset];
$menu['NEXT'] = !empty($ids[$offset+1]) ? $ids[$offset+1] : '';
}
return $menu;
}
function menu($module, $offset, $isAuditEnabled, $saveAndContinue = false ){
$html_text = "";
if($offset < 0) {
$offset = 0;
}
//this check if require in cases when you visit the edit view before visiting that modules list view.
//you can do this easily either from home or activies or sitemap.
$stored_vcr_query=SugarVCR::retrieve($module);
if(!empty($_REQUEST['record']) and !empty($stored_vcr_query) and isset($_REQUEST['offset']) and (empty($_REQUEST['isDuplicate']) or $_REQUEST['isDuplicate'] == 'false')){ // bug 15893 - only show VCR if called as an element in a set of records
//syncing with display offset;
$offset++;
$action = (!empty($_REQUEST['action']) ? $_REQUEST['action'] : 'EditView');
//$html_text .= "<tr class='pagination'>\n";
//$html_text .= "<td COLSPAN=\"20\" style='padding: 0px;'>\n";
$html_text .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"><tr>\n";
$list_URL = 'index.php?action=index&module='.$module;
$current_page = floor($offset / 20) * 20;
$list_URL .= '&offset='.$current_page;
$menu = SugarVCR::play($module, $offset);
if($saveAndContinue){
if(!empty($menu['NEXT'])){
$return_action = 'EditView';
$return_id = $menu['NEXT'];
$list_URL = 'index.php?action=EditView&module='.$module.'&record='.$return_id.'&offset='.($offset+1);
$list_link = "<button type='button' id='save_and_continue' class='button' title='{$GLOBALS['app_strings']['LBL_SAVE_AND_CONTINUE']}' onClick='this.form.action.value=\"Save\";if(check_form(\"EditView\")){sendAndRedirect(\"EditView\", \"{$GLOBALS['app_strings']['LBL_SAVING']} {$module}...\", \"$list_URL\");}'>".$GLOBALS['app_strings']['LBL_SAVE_AND_CONTINUE']."</button>";
}else
$list_link = "";
}else
$list_link = "";
$previous_link = "";
$next_link = "";
if(!empty($menu['PREV'])) {
//$previous_link = "<a href='index.php?module=$module&action=$action&offset=".($offset-1)."&record=".$menu['PREV']."' >".SugarThemeRegistry::current()->getImage("previous","alt='".$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'").'&nbsp;'.$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."</a>";
$href = "index.php?module=$module&action=$action&offset=".($offset-1)."&record=".$menu['PREV'];
$previous_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']}' onClick='document.location.href=\"$href\";'>".SugarThemeRegistry::current()->getImage("previous","alt='".$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'")."</button>";
}
else
$previous_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']}' disabled>".SugarThemeRegistry::current()->getImage("previous_off","alt='".$GLOBALS['app_strings']['LNK_LIST_PREVIOUS']."' border='0' align='absmiddle'")."</button>";
if(!empty($menu['NEXT'])) {
//$next_link = "<a href='index.php?module=$module&action=$action&offset=".($offset+1)."&record=".$menu['NEXT']."' >".$GLOBALS['app_strings']['LNK_LIST_NEXT'].'&nbsp;'.SugarThemeRegistry::current()->getImage("next","alt='".$GLOBALS['app_strings']['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</a>";
$href = "index.php?module=$module&action=$action&offset=".($offset+1)."&record=".$menu['NEXT'];
$next_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_NEXT']}' onClick='document.location.href=\"$href\";'>".SugarThemeRegistry::current()->getImage("next","alt='".$GLOBALS['app_strings']['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</button>";
}
else
$next_link = "<button type='button' class='button' title='{$GLOBALS['app_strings']['LNK_LIST_NEXT']}' disabled>".SugarThemeRegistry::current()->getImage("next_off","alt='".$GLOBALS['app_strings']['LNK_LIST_NEXT']."' border='0' align='absmiddle'")."</button>";
if(!empty($_SESSION[$module. 'total'])){
$count = $offset .' '. $GLOBALS['app_strings']['LBL_LIST_OF'] . ' ' . $_SESSION[$module. 'total'];
if(!empty($GLOBALS['sugar_config']['disable_count_query'])
&& ( ($_SESSION[$module. 'total']-1) % $GLOBALS['sugar_config']['list_max_entries_per_page'] == 0 ) ) {
$count .= '+';
}
}else{
$count = $offset;
}
$html_text .= "<td nowrap align='right' >".$list_link."&nbsp;&nbsp;&nbsp;&nbsp;<span class='pagination'>".$previous_link."&nbsp;&nbsp;(".$count.")&nbsp;&nbsp;".$next_link."</span>&nbsp;&nbsp;</td>";
$html_text .= "</tr></table>";//</td></tr>";
}
return $html_text;
}
function record($module, $offset){
$GLOBALS['log']->debug('SUGARVCR is recording more records');
$start = max(0, $offset - VCRSTART);
$index = $start;
$db = DBManagerFactory::getInstance();
$result = $db->limitQuery(SugarVCR::retrieve($module),$start,($offset+VCREND),false);
$index++;
$ids = array();
while(($row = $db->fetchByAssoc($result)) != null){
$ids[$index] = $row['id'];
$index++;
}
//now that we have the array of ids, store this in the session
$_SESSION[$module.'QUERY_ARRAY'] = $ids;
return $ids;
}
function recordIDs($module, $rids, $offset, $totalCount){
$index = $offset;
$index++;
$ids = array();
foreach($rids as $id){
$ids[$index] = $id;
$index++;
}
//now that we have the array of ids, store this in the session
$_SESSION[$module.'QUERY_ARRAY'] = $ids;
$_SESSION[$module.'total'] = $totalCount;
}
function erase($module){
unset($_SESSION[$module. 'QUERY_ARRAY']);
}
}
?>