From 5c189449e1c327ab65dd8f404aa352032ed15a02 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 20 Oct 2017 17:02:26 +0200 Subject: [PATCH] Move default value for user expense report on tab expense report --- htdocs/core/class/html.form.class.php | 12 ++- htdocs/expensereport/list.php | 128 +++++++++++++++++++++++--- htdocs/langs/en_US/admin.lang | 2 - htdocs/langs/en_US/trips.lang | 2 + htdocs/langs/en_US/website.lang | 2 +- htdocs/user/bank.php | 51 +++++----- htdocs/user/card.php | 120 ------------------------ htdocs/user/class/user.class.php | 2 +- htdocs/websites/index.php | 2 +- 9 files changed, 147 insertions(+), 174 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e29b7dbeaa0..d5118d66824 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -438,8 +438,11 @@ class Form $s='';$textfordialog=''; - $htmltext=str_replace('"',""",$htmltext); - if ($tooltiptrigger != '') + if ($tooltiptrigger == '') + { + $htmltext=str_replace('"',""",$htmltext); + } + else { $classfortooltip='classfortooltiponclick'; $textfordialog.=''; @@ -6448,7 +6451,7 @@ class Form */ function selectExpenseCategories($selected='', $htmlname='fk_c_exp_tax_cat', $useempty=0, $excludeid=array(), $target='', $default_selected=0, $params=array()) { - global $db,$conf,$langs; + global $db, $conf, $langs, $user; $sql = 'SELECT rowid, label FROM '.MAIN_DB_PREFIX.'c_exp_tax_cat WHERE active = 1'; $sql.= ' AND entity IN (0,'.getEntity('').')'; @@ -6459,13 +6462,14 @@ class Form if ($resql) { $out = ''; + if (! empty($htmlname) && $user->admin) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); if (!empty($target)) { diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index 6ad9f0d80d8..3110aa37459 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php'; $langs->load("companies"); $langs->load("users"); @@ -126,6 +127,10 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab } } +$canedituser=(! empty($user->admin) || $user->rights->user->user->creer); + +$object = new ExpenseReport($db); +$objectuser = new User($db); /* @@ -172,6 +177,51 @@ if (empty($reshook)) $permtodelete = $user->rights->expensereport->supprimer; $uploaddir = $conf->expensereport->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + + if ($action == 'update' && ! $cancel) + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + if ($canedituser) // Case we can edit all field + { + $error = 0; + + if (!$error) + { + $objectuser->fetch($id); + + $objectuser->oldcopy = clone $objectuser; + + $db->begin(); + + $objectuser->default_range = GETPOST('default_range'); + $objectuser->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat'); + + if (!$error) { + $ret = $objectuser->update($user); + if ($ret < 0) { + $error++; + if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + setEventMessages($langs->trans("ErrorLoginAlreadyExists", $objectuser->login), null, 'errors'); + } + else + { + setEventMessages($objectuser->error, $objectuser->errors, 'errors'); + } + } + } + + if (!$error && !count($objectuser->errors)) { + setEventMessages($langs->trans("UserModified"), null, 'mesgs'); + $db->commit(); + } + else { + $db->rollback(); + } + } + } + } } @@ -338,7 +388,7 @@ if ($resql) if ($optioncss != '') print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -355,9 +405,43 @@ if ($resql) dol_banner_tab($fuser,'id',$linkback,$user->rights->user->user->lire || $user->admin); + print '
'; print '
'; - print '
'; + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) + { + print ''; + + if ($action == 'edit') + { + print ''; + print ''; + + print ''; + print ''; + } + else + { + print ''; + print ''; + + print ''; + print ''; + } + + print '
'.$langs->trans("DefaultCategoryCar").''; + print $form->selectExpenseCategories($fuser->default_c_exp_tax_cat, 'default_c_exp_tax_cat', 1); + print '
'.$langs->trans("DefaultRangeNumber").''; + $maxRangeNum = ExpenseReportIk::getMaxRangeNumber($fuser->default_c_exp_tax_cat); + print $form->selectarray('default_range', range(0, $maxRangeNum), $fuser->default_range); + print '
'.$langs->trans("DefaultCategoryCar").''; + print dol_getIdFromCode($db, $fuser->default_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label'); + print '
'.$langs->trans("DefaultRangeNumber").''; + print $fuser->default_range; + print '
'; + } + + print '
'; /*if (empty($conf->global->HOLIDAY_HIDE_BALANCE)) { @@ -370,17 +454,31 @@ if ($resql) dol_fiche_end(); - print '
'; - - $canedit=(($user->id == $user_id && $user->rights->expensereport->creer) || ($user->id != $user_id)); - - // Boutons d'actions - if ($canedit) + if ($action != 'edit') { - print ''.$langs->trans("AddTrip").''; - } + print '
'; - print '
'; + if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) + { + print ''.$langs->trans("Modify").''; + } + + $canedit=(($user->id == $user_id && $user->rights->expensereport->creer) || ($user->id != $user_id)); + + // Boutons d'actions + if ($canedit) + { + print ''.$langs->trans("AddTrip").''; + } + + print '
'; + } + else + { + print '
'; + print ''; + print '

'; + } } else { @@ -653,22 +751,22 @@ if ($resql) } // Start date if (! empty($arrayfields['d.date_debut']['checked'])) { - print ''.($obj->date_debut > 0 ? dol_print_date($obj->date_debut, 'day') : '').''; + print ''.($obj->date_debut > 0 ? dol_print_date($db->jdate($obj->date_debut), 'day') : '').''; if (! $i) $totalarray['nbfield']++; } // End date if (! empty($arrayfields['d.date_fin']['checked'])) { - print ''.($obj->date_fin > 0 ? dol_print_date($obj->date_fin, 'day') : '').''; + print ''.($obj->date_fin > 0 ? dol_print_date($db->jdate($obj->date_fin), 'day') : '').''; if (! $i) $totalarray['nbfield']++; } // Date validation if (! empty($arrayfields['d.date_valid']['checked'])) { - print ''.($obj->date_valid > 0 ? dol_print_date($obj->date_valid, 'day') : '').''; + print ''.($obj->date_valid > 0 ? dol_print_date($db->jdate($obj->date_valid), 'day') : '').''; if (! $i) $totalarray['nbfield']++; } // Date approval if (! empty($arrayfields['d.date_approve']['checked'])) { - print ''.($obj->date_approve > 0 ? dol_print_date($obj->date_approve, 'day') : '').''; + print ''.($obj->date_approve > 0 ? dol_print_date($db->jdate($obj->date_approve), 'day') : '').''; if (! $i) $totalarray['nbfield']++; } // Amount HT diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 3f66ea2fedd..7756f5cc3e5 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1170,8 +1170,6 @@ RuleForGeneratedPasswords=Rule to generate suggested passwords or validate passw DisableForgetPasswordLinkOnLogonPage=Do not show the link "Forget password" on login page UsersSetup=Users module setup UserMailRequired=EMail required to create a new user -DefaultCategoryCar=Default car category -DefaultRangeNumber=Default range number ##### HRM setup ##### HRMSetup=HRM module setup ##### Company setup ##### diff --git a/htdocs/langs/en_US/trips.lang b/htdocs/langs/en_US/trips.lang index da4b3efa8f8..9ec96d98ff4 100644 --- a/htdocs/langs/en_US/trips.lang +++ b/htdocs/langs/en_US/trips.lang @@ -73,6 +73,8 @@ EX_FUE_VP=Fuel PV EX_TOL_VP=Toll PV EX_PAR_VP=Parking PV EX_CAM_VP=PV maintenance and repair +DefaultCategoryCar=Default transportation mode +DefaultRangeNumber=Default range number ErrorDoubleDeclaration=You have declared another expense report into a similar date range. AucuneLigne=There is no expense report declared yet diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index bd4db42c2fa..d20566ac397 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -39,7 +39,7 @@ VirtualHostUrlNotDefined=URL of the virtual host served by external web server n NoPageYet=No pages yet SyntaxHelp=Help on specific syntax tips YouCanEditHtmlSourceckeditor=You can edit HTML source code using the "Source" button in editor. -YouCanEditHtmlSource=You can include PHP code into this source using tags <?php ?>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.

You can also include content of another Page/Container with the following syntax:
<?php dolIncludeHtmlContent($websitekey.'/alias_of_content_to_include.php'); ?>

To include a link to download a file stored into the documents directory, use the document.php wrapper:
Example, for a file into documents/ecm (need to be logged), syntax is:
<a href="/document.php?modulepart=ecm&file=relative_dir/filename.ext">
For same file into documents/ecm (open access using the sharing hash key), syntax is:
<a href="/document.php?modulepart=ecm&file=relative_dir/filename.ext&hashp=publicsharekeyoffile">
For a file into documents/media (open directory for public access), syntax is:
<a href="/document.php?modulepart=medias&file=relative_dir/filename.ext">

To include an image stored into the documents directory, use the viewimage.php wrapper:
Example, for an image into documents/media (open access), syntax is:
<a href="/viewimage.php?modulepart=medias&file=relative_dir/filename.ext"> +YouCanEditHtmlSource=
You can include PHP code into this source using tags <?php ?>. The following global variables are available: $conf, $langs, $db, $mysoc, $user, $website.

You can also include content of another Page/Container with the following syntax:
<?php dolIncludeHtmlContent($websitekey.'/alias_of_container_to_include.php'); ?>

To include a link to download a file stored into the documents directory, use the document.php wrapper:
Example, for a file into documents/ecm (need to be logged), syntax is:
<a href="/document.php?modulepart=ecm&file=relative_dir/filename.ext">
For same file into documents/ecm (open access using the sharing hash key), syntax is:
<a href="/document.php?modulepart=ecm&file=relative_dir/filename.ext&hashp=publicsharekeyoffile">
For a file into documents/media (open directory for public access), syntax is:
<a href="/document.php?modulepart=medias&file=relative_dir/filename.ext">

To include an image stored into the documents directory, use the viewimage.php wrapper:
Example, for an image into documents/media (open access), syntax is:
<a href="/viewimage.php?modulepart=medias&file=relative_dir/filename.ext">
ClonePage=Clone page/container CloneSite=Clone site ConfirmClonePage=Please enter code/alias of new page and if it is a translation of the cloned page. diff --git a/htdocs/user/bank.php b/htdocs/user/bank.php index 6677e240a04..0f26169adf3 100644 --- a/htdocs/user/bank.php +++ b/htdocs/user/bank.php @@ -312,18 +312,14 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco $resql=$db->query($sql); if ($resql) { - $var=true; $num = $db->num_rows($resql); - if ($num > 0) - { - print ''; + print '
'; - print ''; - print ''; - print ''; - } + print ''; + print ''; + print ''; $i = 0; while ($i < $num && $i < $MAXLIST) @@ -343,7 +339,8 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco } $db->free($resql); - if ($num > 0) print "
'; - print '
'.$langs->trans("LastSalaries",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllSalaries").' '.$num.'
'; + print '
'.$langs->trans("LastSalaries",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllSalaries").' '.$num.'
"; + if ($num <= 0) print ''.$langs->trans("None").''; + print ""; } else { @@ -369,18 +366,14 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco $resql=$db->query($sql); if ($resql) { - $var=true; $num = $db->num_rows($resql); - if ($num > 0) - { - print ''; + print '
'; - print ''; - print ''; - print ''; - } + print ''; + print ''; + print ''; $i = 0; while ($i < $num && $i < $MAXLIST) @@ -402,7 +395,8 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco } $db->free($resql); - if ($num > 0) print "
'; - print '
'.$langs->trans("LastHolidays",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllHolidays").' '.$num.'
'; + print '
'.$langs->trans("LastHolidays",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllHolidays").' '.$num.'
"; + if ($num <= 0) print ''.$langs->trans("None").''; + print ""; } else { @@ -428,18 +422,14 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco $resql=$db->query($sql); if ($resql) { - $var=true; $num = $db->num_rows($resql); - if ($num > 0) - { - print ''; + print '
'; - print ''; - print ''; - print ''; - } + print ''; + print ''; + print ''; $i = 0; while ($i < $num && $i < $MAXLIST) @@ -460,7 +450,8 @@ if ($action != 'edit' && $action != 'create') // If not bank account yet, $acco } $db->free($resql); - if ($num > 0) print "
'; - print '
'.$langs->trans("LastExpenseReports",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllExpenseReports").' '.$num.'
'; + print '
'.$langs->trans("LastExpenseReports",($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllExpenseReports").' '.$num.'
"; + if ($num <= 0) print ''.$langs->trans("None").''; + print ""; } else { diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 106fa322cf1..a62ac060d74 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -46,7 +46,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; -if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php'; $id = GETPOST('id','int'); $action = GETPOST('action','alpha'); @@ -370,9 +369,6 @@ if (empty($reshook)) { $dateemployment = dol_mktime(0, 0, 0, GETPOST('dateemploymentmonth'), GETPOST('dateemploymentday'), GETPOST('dateemploymentyear')); $object->dateemployment = $dateemployment; - $object->default_range = GETPOST('default_range'); - $object->default_c_exp_tax_cat = GETPOST('default_c_exp_tax_cat'); - if (! empty($conf->multicompany->enabled)) { if (! empty($_POST["superadmin"])) @@ -1126,20 +1122,6 @@ if ($action == 'create' || $action == 'adduserldap') } */ - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) - { - print ''.$langs->trans("DefaultCategoryCar").''; - print ''; - print $form->selectExpenseCategories($object->default_c_exp_tax_cat, 'default_c_exp_tax_cat', 1); - print ''; - - print ''.$langs->trans("DefaultRangeNumber").''; - print ''; - $maxRangeNum = ExpenseReportIk::getMaxRangeNumber($object->default_c_exp_tax_cat); - print $form->selectarray('default_range', range(0, $maxRangeNum), $object->default_range); - print ''; - } - // Other attributes $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook @@ -1540,19 +1522,6 @@ else print ''.dol_print_date($object->datepreviouslogin,"dayhour").''; print "\n"; - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) - { - print ''.$langs->trans("DefaultCategoryCar").''; - print ''; - print dol_getIdFromCode($db, $object->default_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label'); - print ''; - - print ''.$langs->trans("DefaultRangeNumber").''; - print ''; - print $object->default_range; - print ''; - } - // Multicompany // This is now done with hook formObjectOptions (included into /core/tpl/extrafields_view.tpl.php) /* @@ -1737,81 +1706,6 @@ else include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; - /* - if ($action == 'presend') - { - // Show email form - - // By default if $action=='presend' - $titreform='SendMail'; - $topicmail=1; - $action='send'; - $modelmail='user'; - - print '
'; - print '
'; - print load_fiche_titre($langs->trans($titreform)); - - dol_fiche_head(); - - // Define output language - $outputlangs = $langs; - $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) - $newlang = $_REQUEST['lang_id']; - //if ($conf->global->MAIN_MULTILANGS && empty($newlang)) - // $newlang = $object->thirdparty->default_lang; - - // Cree l'objet formulaire mail - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail = new FormMail($db); - $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); - $formmail->fromtype = (GETPOST('fromtype')?GETPOST('fromtype'):(!empty($conf->global->MAIN_MAIL_DEFAULT_FROMTYPE)?$conf->global->MAIN_MAIL_DEFAULT_FROMTYPE:'user')); - - if($formmail->fromtype === 'user'){ - $formmail->fromid = $user->id; - - } - $formmail->trackid='thi'.$object->id; - if (! empty($conf->global->MAIN_EMAIL_ADD_TRACK_ID) && ($conf->global->MAIN_EMAIL_ADD_TRACK_ID & 2)) // If bit 2 is set - { - include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; - $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'thi'.$object->id); - } - $formmail->withfrom=1; - $formmail->withtopic=$topicmail; - $formmail->withto=GETPOST('sendto')?GETPOST('sendto'):$object->email; - $formmail->withtofree=1; - $formmail->withtocc=1; - $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC; - $formmail->withfile=2; - $formmail->withbody=1; - $formmail->withdeliveryreceipt=1; - $formmail->withcancel=1; - // Tableau des substitutions - $formmail->setSubstitFromObject($object, $outputlangs); - $formmail->substit['__LASTNAME__']=$object->lastname; - $formmail->substit['__FIRSTNAME__']=$object->firstname; - - // Tableau des parametres complementaires du post - $formmail->param['action']=$action; - $formmail->param['models']=$modelmail; - $formmail->param['models_id']=GETPOST('modelmailselected','int'); - $formmail->param['socid']=$object->id; - $formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - - // Init list of files - if (GETPOST("mode")=='init') - { - $formmail->clear_attached_files(); - $formmail->add_attached_files($file,basename($file),dol_mimetype($file)); - } - print $formmail->get_form(); - - dol_fiche_end(); - } - */ - if (GETPOST('action','aZ09') != 'presend' && GETPOST('action','aZ09') != 'send') { /* @@ -2481,20 +2375,6 @@ else print "\n"; } - if (!empty($conf->global->MAIN_USE_EXPENSE_IK)) - { - print ''.$langs->trans("DefaultCategoryCar").''; - print ''; - print $form->selectExpenseCategories($object->default_c_exp_tax_cat, 'default_c_exp_tax_cat', 1); - print ''; - - print ''.$langs->trans("DefaultRangeNumber").''; - print ''; - $maxRangeNum = ExpenseReportIk::getMaxRangeNumber($object->default_c_exp_tax_cat); - print $form->selectarray('default_range', range(0, $maxRangeNum), $object->default_range); - print ''; - } - // Multicompany // This is now done with hook formObjectOptions /* diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 49e95cd40a3..806be3e5e36 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -201,7 +201,7 @@ class User extends CommonObject $sql.= " u.color,"; $sql.= " u.dateemployment,"; $sql.= " u.ref_int, u.ref_ext,"; - $sql.= " u.default_range, u.default_c_exp_tax_cat,"; + $sql.= " u.default_range, u.default_c_exp_tax_cat,"; // Expense report default mode $sql.= " c.code as country_code, c.label as country,"; $sql.= " d.code_departement as state_code, d.nom as state"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index fa33f9bae43..28ebb4d439e 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -1386,7 +1386,7 @@ if (count($object->records) > 0) if (GETPOST('editsource', 'alpha') || GETPOST('editcontent', 'alpha')) { $htmltext=$langs->transnoentitiesnoconv("YouCanEditHtmlSource"); - print $form->textwithpicto($langs->trans("SyntaxHelp"), $htmltext, 1, 'help', 'inline-block', 0, 2, 'tooltipsubstitution'); + print $form->textwithpicto($langs->trans("SyntaxHelp"), $htmltext, 1, 'help', 'inline-block', 1, 2, 'tooltipsubstitution'); } print ''; // end websitehelp