[Vtigercrm-developers] Add upload file to Task
Sukhdev Mohan
s.mohan at myti.it
Tue Mar 10 08:37:13 GMT 2020
Hi Uma,
Somehow I solved it!
As you say UI Type 61 and have added this
{*<!--
/*********************************************************************************
** The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
*
********************************************************************************/
-->*}
{strip}
{assign var="FIELD_INFO" value=$FIELD_MODEL->getFieldInfo()}
{assign var=FILE_LOCATION_TYPE_FIELD value=$RECORD_STRUCTURE['LBL_FILE_INFORMATION']['filelocationtype']}
{if $FILE_LOCATION_TYPE_FIELD eq NULL}
{assign var=DOCUMENTS_MODULE_MODEL value=Vtiger_Module_Model::getInstance('Documents')}
{assign var=FILE_LOCATION_TYPE_FIELD value=$DOCUMENTS_MODULE_MODEL->getField('filelocationtype')}
{/if}
{assign var=IS_INTERNAL_LOCATION_TYPE value=$FILE_LOCATION_TYPE_FIELD->get('fieldvalue') neq 'E'}
{assign var=IS_EXTERNAL_LOCATION_TYPE value=$FILE_LOCATION_TYPE_FIELD->get('fieldvalue') eq 'E'}
{assign var=FIELD_VALUE value=$FIELD_MODEL->get('fieldvalue')}
{assign var="SPECIAL_VALIDATOR" value=$FIELD_MODEL->getValidator()}
<div class="fileUploadContainer">
{if $IS_EXTERNAL_LOCATION_TYPE}
<input type="text" class="inputElement {if $FIELD_MODEL->isNameField()}nameField{/if}" name="{$FIELD_MODEL->getFieldName()}"
value="{if $IS_EXTERNAL_LOCATION_TYPE}{$FIELD_VALUE}{/if}" {if !empty($SPECIAL_VALIDATOR)} data-validator='{Zend_Json::encode($SPECIAL_VALIDATOR)}' {/if}
{if $FIELD_INFO["mandatory"] eq true} data-rule-required="true" {/if}
{if count($FIELD_INFO['validator'])}
data-specific-rules='{ZEND_JSON::encode($FIELD_INFO["validator"])}'
{/if}
/>
{else}
<div class="fileUploadBtn btn btn-primary">
<span><i class="fa fa-laptop"></i> {vtranslate('LBL_UPLOAD', $MODULE)}</span>
<input type="file" class="inputElement {if $FIELD_MODEL->isNameField()}nameField{/if}" name="{$FIELD_MODEL->getFieldName()}"
value="{if $IS_INTERNAL_LOCATION_TYPE} {$FIELD_VALUE} {/if}" {if !empty($SPECIAL_VALIDATOR)}data-validator='{Zend_Json::encode($SPECIAL_VALIDATOR)}'{/if} {if $IS_INTERNAL_LOCATION_TYPE && !empty($FIELD_VALUE)} style="width:86px;" {/if}
{if $FIELD_INFO["mandatory"] eq true} data-rule-required="true" {/if}
{if count($FIELD_INFO['validator'])}
data-specific-rules='{ZEND_JSON::encode($FIELD_INFO["validator"])}'
{/if}
/>
</div>
{/if}
<div class="uploadedFileDetails {if $IS_EXTERNAL_LOCATION_TYPE}hide{/if}">
<div class="uploadedFileSize"></div>
<div class="uploadedFileName">
{if $IS_INTERNAL_LOCATION_TYPE && !empty($FIELD_VALUE)}
[{$FIELD_VALUE}]
{/if}
</div>
<div class="uploadFileSizeLimit redColor">
{vtranslate('LBL_MAX_UPLOAD_SIZE',$MODULE)} <span class="maxUploadSize" data-value="{$MAX_UPLOAD_LIMIT_BYTES}">{$MAX_UPLOAD_LIMIT_MB}{vtranslate('MB',$MODULE)}</span>
</div>
</div>
</div>
{/strip}
Customizing the layouts/v7/modules/Vtiger/partials/EditViewContents.tpl with this
{if $FIELD_MODEL->get('uitype') neq '83'}
<td class="fieldValue" {if $FIELD_MODEL->getFieldDataType() eq 'boolean'} style="width:25%" {/if} {if $FIELD_MODEL->get('uitype') eq '19'} colspan="3" {assign var=COUNTER value=$COUNTER+1} {/if}>
{if $MODULE eq 'Calendar' && $FIELD_MODEL->get('uitype') eq '69'}
{include file=vtemplate_path('uitypes/File.tpl',$MODULE)}
{else}
{include file=vtemplate_path($FIELD_MODEL->getUITypeModel()->getTemplateName(),$MODULE)}
{/if}
</td>
{/if}
But there is problem when editing: the attachments is deleted but not updated with the new upload. I’ve modified CRMEntity.php in this way:
if ($insertion_mode == 'edit') {
//Track the update and update only when needed - vikas
$updateFieldValues = @array_combine($updateColumnNames, $update_params);
$changedFields = $this->column_fields->getChanged();
if(count($changedFields) > 0) {
$update = array();
$update_params = array();
foreach($changedFields as $field) {
$fieldColumn = $updateFieldNameColumnNameMap[$field];
if(@array_key_exists($fieldColumn, $updateFieldValues)) {
array_push($update, $fieldColumn.'=?');
array_push($update_params, $updateFieldValues[$fieldColumn]);
}
}
if ($module == "Calendar") {
array_push($update, 'allegato=?');
if (array_key_exists("allegato", $updateFieldValues)) {
array_push($update_params, $updateFieldValues["allegato"]);
} elseif($updateFieldValues["allegato"] == " 0000 ") {
array_push($update_params, '');
}
}
if (count($update) > 0) {
$sql1 = "UPDATE $table_name SET " . implode(",", $update) . " WHERE " . $this->tab_name_index[$table_name] . "=?";
array_push($update_params, $this->id);
if(Vtiger_Functions::isUserSpecificFieldTable($table_name, $module)){
$sql1 .= ' AND userid = ?';
array_push($update_params, $current_user->id);
}
$adb->pquery($sql1, $update_params);
}
}
} else {
$sql1 = "insert into $table_name(" . implode(",", $column) . ") values(" . generateQuestionMarks($value) . ")";
$adb->pquery($sql1, $value);
}
Still there’s one problem: you can’t delete an attached Item (delete an attachment and have the field empty)… Any idea?
Best Regards,
Sukhdev Mohan
———————————
Cel. (+39) 320 7020345
Email s.mohan at myti.it
> Il giorno 10 mar 2020, alle ore 09:10, Uma S <uma.s at vtiger.com> ha scritto:
>
> Hi Sukhdev,
>
> Do try with uitype 61 for file type field. Check this for reference <https://sc.vtiger.in/screenshots/uma-sc-at-10-03-2020-13-39-29.png> (660_to_700.php)
>
> On Wed, Feb 26, 2020 at 4:31 PM Alan Lord <alanslists at gmail.com <mailto:alanslists at gmail.com>> wrote:
> On 26/02/2020 10:51, Sukhdev Mohan wrote:
> > Hi alan,
> >
> > Use case is as follows: the sales person need to add documents (PDF or
> > Images) while adding tasks, that’s why we discarded the relationship
> > with documents. How can I do?
>
> See my earlier reply; it is not trivial.
>
> You will need to clone a fair bit of code/functionality from the other
> relevant modules. Take a look at the Documents and Contacts/Products
> modules to see how they do it.
>
>
> Al
>
>
> _______________________________________________
> http://www.vtiger.com/ <http://www.vtiger.com/>
>
> --
> With
> Best Regards
> Uma.S
> Vtiger Team
> _______________________________________________
> http://www.vtiger.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20200310/064f027f/attachment-0001.html>
More information about the vtigercrm-developers
mailing list