Hi Agnul,
i have fixed this some time ago, i think that the attached file is
the only thing that i have modify in order to fix this
put it in : doceboCore/modules/field/
Cya,
Fabio
agnul ha scritto:
> Hi,
> In our docebo installation we've added a few custom fields to the
> teacher's profiles. One of those is an upload field, allowing to
> upload a cv file. When I look at the teacher profile I would expect
> the link next to the "browse" button to point to the uploaded file if
> any, but instead I get a 404. The URL I have is
> .../doceboCore/
> fo=special&type_field=upload&id_user=20427&id_common=19
> I guess something is missing between "doceboCore" and "fo=special",
> and looking at the code I guess that getUrl() for upload fields
> returns an empty string. This could be because setUrl() is never
> called when creating fields via "eval ('return new...')" in
> lib.field.php. Any idea how to fix that?
> Thanks in advance.
> A.
> No virus found in this incoming message.
> Checked by AVG - http://www.avg.com
> Version: 8.0.138 / Virus Database: 270.4.6/1539 - Release Date: 07/07/2008 18.35
--
Fabio Pirovano
Docebo SRL - The open source e-learning company
Tel. +39 039-2323286
Fax +39 039-3309936
http://www.docebo.com
[
class.upload.php 23K ]
*/
require_once(dirname(__FILE__).'/class.field.php');
class Field_Upload extends Field {
/**
* class constructor
*/
function Field_Upload($id_common) {
parent::Field($id_common);
}
/**
* this function is useful for field recognize
*
* @return string return the identifier of the field
*
* @access public
*/
function getFieldType() {
return 'upload';
}
/**
* this function create a new field for future use
*
* @param string $back indicates the return url
* @return nothing
*
* @access public
*/
function create($back) {
$back_coded = htmlentities(urlencode($back));
$array_lang = array();
$std_lang =& DoceboLanguage::createInstance('standard');
$lang =& DoceboLanguage::createInstance('field');
$array_lang = $GLOBALS['globLangManager']->getAllLangCode();
$out =& $GLOBALS['page'];
if(isset($_POST['undo'])) {
//undo action
jumpTo($back.'&result=undo');
}
if(isset($_POST['save_field_'.$this->getFieldType()])) {
//insert mandatory translation
$mand_lang = getLanguage();
if(isset($_POST['show_on_platform'])) {
while(list($code, ) = each($_POST['show_on_platform']))
$show_on .= $code.',';
}
//insert mandatory translation
$mand_lang = getLanguage();
//control if all is ok
if(!isset($_POST['new_upload'][$mand_lang])) {
$out->add(
getErrorUi($lang->def('_ERR_MUST_DEF_MANADATORY_TRANSLATION'))
.getBackUi($this->getUrl().'&type_field='
.$this->getFieldType().'&back='.$back_coded, $std_lang->def('_BACK')),
'content'
);
return;
}
if($_POST['new_upload'][$mand_lang] == $lang->def('_NEW_FIELD') || trim($_POST['new_upload'][$mand_lang]) == '') {
$out->add(
getErrorUi($lang->def('_ERR_MUST_DEF_MANADATORY_TRANSLATION'))
.getBackUi($this->getUrl().'&type_field='
.$this->getFieldType().'&back='.$back_coded, $std_lang->def('_BACK')),
'content'
);
return;
}
//insert mandatory field
if(!mysql_query("
INSERT INTO ".$this->_getMainTable()."
(type_field, lang_code, translation, show_on_platform, use_multilang) VALUES
('".$this->getFieldType()."', '".$mand_lang."', '".$_POST['new_upload'][$mand_lang]."', '".$show_on."', '".$use_multilang."') ")) {
jumpTo($back.'&result=fail');
}
list($id_common) = mysql_fetch_row(mysql_query("SELECT LAST_INSERT_ID()"));
if(!mysql_query("
UPDATE ".$this->_getMainTable()."
SET id_common = '".(int)$id_common."'
WHERE idField = '".(int)$id_common."'")) {
jumpTo($back.'&result=fail');
}
$re = true;
//insert other field
foreach($_POST['new_upload'] as $lang_code => $translation) {
if($mand_lang != $lang_code && $translation != $lang->def('_NEW_FIELD') && trim($translation) != '') {
$re_ins = mysql_query("
INSERT INTO ".$this->_getMainTable()."
(type_field, id_common, lang_code, translation, show_on_platform, use_multilang) VALUES
('".$this->getFieldType()."', '".(int)$id_common."', '".$lang_code."', '".$translation."', '".$show_on."', '".$use_multilang."') ");
$re = $re && $re_ins;
}
}
jumpTo($back.'&result='.( $re ? 'success' : 'fail'));
}
require_once($GLOBALS['where_framework'].'/lib/lib.form.php');
$form = new Form();
$out->setWorkingZone('content');
$out->add('
');
$out->add(
$form->getFormHeader($lang->def('_NEW_UPLOAD'))
.$form->openForm('create_'.$this->getFieldType(), $this->getUrl())
.$form->openElementSpace()
.$form->getHidden('type_field', 'type_field', $this->getFieldType())
.$form->getHidden('back', 'back', $back_coded)
);
$mand_lang = getLanguage();
foreach($array_lang as $k => $lang_code ) {
$out->add(
$form->getTextfield(( ($mand_lang == $lang_code) ? '*' : '' ).$lang_code,
'new_upload_'.$lang_code,
'new_upload['.$lang_code.']',
255,
'',
$lang_code.' '.$lang->def('_NEW_FIELD') )
);
}
$GLOBALS['page']->add($this->getMultiLangCheck(), 'content');
$GLOBALS['page']->add($this->getShowOnPlatformFieldset(), 'content');
$out->add(
$form->closeElementSpace()
.$form->openButtonSpace()
.$form->getButton('save_field', 'save_field_'.$this->getFieldType(), $std_lang->def('_CREATE', 'standard'))
.$form->getButton('undo', 'undo', $std_lang->def('_UNDO', 'standard'))
.$form->closeButtonSpace()
.$form->closeForm()
);
$out->add('
');
}
/**
* this function manage a field
*
* @param string $back indicates the return url
* @return nothing
*
* @access public
*/
function edit( $back ) {
$back_coded = htmlentities(urlencode($back));
$array_lang = array();
$std_lang =& DoceboLanguage::createInstance('standard');
$lang =& DoceboLanguage::createInstance('field');
$array_lang = $GLOBALS['globLangManager']->getAllLangCode();
$out =& $GLOBALS['page'];
if(isset($_POST['undo'])) {
//undo action
jumpTo($back.'&result=undo');
}
if(isset($_POST['save_field_'.$this->getFieldType()])) {
//insert mandatory translation
$mand_lang = getLanguage();
//control if all is ok
if(!isset($_POST['new_upload'][$mand_lang])) {
$out->add(
getErrorUi($lang->def('_ERR_MUST_DEF_MANADATORY_TRANSLATION'))
.getBackUi($this->getUrl().'&type_field='
.$this->getFieldType().'&back='.$back_coded, $std_lang->def('_BACK')),
'content'
);
return;
}
if($_POST['new_upload'][$mand_lang] == $lang->def('_NEW_FIELD') || trim($_POST['new_upload'][$mand_lang]) == '') {
$out->add(
getErrorUi($lang->def('_ERR_MUST_DEF_MANADATORY_TRANSLATION'))
.getBackUi($this->getUrl().'&type_field='
.$this->getFieldType().'&back='.$back_coded, $std_lang->def('_BACK')),
'content'
);
return;
}
$existsing_translation = array();
$re_trans = mysql_query("
SELECT lang_code
FROM ".$this->_getMainTable()."
WHERE id_common = '".$this->id_common."'");
while(list($l_code) = mysql_fetch_row($re_trans)) {
$existsing_translation[$l_code] = 1;
}
$use_multilang =(isset($_POST['use_multi_lang']) ? 1 : 0);
$re = true;
if(isset($_POST['show_on_platform'])) {
while(list($code, ) = each($_POST['show_on_platform']))
$show_on .= $code.',';
}
//insert other field
foreach($_POST['new_upload'] as $lang_code => $translation) {
if(isset($existsing_translation[$lang_code])) {
if(!mysql_query("
UPDATE ".$this->_getMainTable()."
SET translation = '".$translation."',
show_on_platform = '".$show_on."',
use_multilang = '".$use_multilang."'
WHERE id_common = '".(int)$this->id_common."' AND lang_code = '".$lang_code."'")) $re = false;
} else {
if(!mysql_query("
INSERT INTO ".$this->_getMainTable()."
(type_field, id_common, lang_code, translation, show_on_platform, use_multilang) VALUES
('".$this->getFieldType()."', '".(int)$this->id_common."', '".$lang_code."', '".$translation."', '".$show_on."', '".$use_multilang."') ")) $re= false;
}
}
jumpTo($back.'&result='.( $re ? 'success' : 'fail'));
}
//load value form database
$re_trans = mysql_query("
SELECT lang_code, translation, show_on_platform, use_multilang
FROM ".$this->_getMainTable()."
WHERE id_common = '".$this->id_common."'");
while(list($l_code, $trans, $show_on, $db_use_multilang) = mysql_fetch_row($re_trans)) {
$translation[$l_code] = $trans;
if(!isset($show_on_platform)) $show_on_platform = array_flip(explode(',', $show_on));
if(!isset($use_multilang)) $use_multilang = $db_use_multilang;
}
require_once($GLOBALS['where_framework'].'/lib/lib.form.php');
$form = new Form();
$out->setWorkingZone('content');
$out->add('
');
$out->add(
$form->getFormHeader($lang->def('_MODIFY_UPLOAD'))
.$form->openForm('create_'.$this->getFieldType(), $this->getUrl())
.$form->openElementSpace()
.$form->getHidden('type_field', 'type_field', $this->getFieldType())
.$form->getHidden('id_common', 'id_common', $this->id_common)
.$form->getHidden('back', 'back', $back_coded)
);
$mand_lang = getLanguage();
foreach($array_lang as $k => $lang_code ) {
$out->add(
$form->getTextfield(( ($mand_lang == $lang_code) ? '*' : '' ).$lang_code,
'new_upload_'.$lang_code,
'new_upload['.$lang_code.']',
255,
( isset($translation[$lang_code]) ? $translation[$lang_code] : '' ),
$lang_code.' '.$lang->def('_NEW_FIELD') )
);
}
$GLOBALS['page']->add($this->getMultiLangCheck($use_multilang), 'content');
$GLOBALS['page']->add($this->getShowOnPlatformFieldset($show_on_platform), 'content');
$out->add(
$form->closeElementSpace()
.$form->openButtonSpace()
.$form->getButton('save_field', 'save_field_'.$this->getFieldType(),
...
read more »