Skip to content

Commit

Permalink
Qual: Mutualize code for actions of editing notes
Browse files Browse the repository at this point in the history
New: Add button 'cancel' to cancel edition of a note (private or public)
  • Loading branch information
eldy committed Jan 11, 2014
1 parent 171e74a commit 23eb0f3
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 299 deletions.
16 changes: 4 additions & 12 deletions htdocs/comm/propal.php
Expand Up @@ -96,6 +96,7 @@
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('propalcard'));

$permissionnote=$user->rights->propale->creer; // Used by the include of actions_setnotes.inc.php


/*
Expand All @@ -105,6 +106,9 @@
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks

include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once


// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes')
{
Expand Down Expand Up @@ -232,18 +236,6 @@
$object->set_ref_client($user, $_POST['ref_client']);
}

else if ($action == 'setnote_public' && $user->rights->propal->creer)
{
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) dol_print_error($db,$object->error);
}

else if ($action == 'setnote_private' && $user->rights->propal->creer)
{
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES),'_private');
if ($result < 0) dol_print_error($db,$object->error);
}

// Create proposal
else if ($action == 'add' && $user->rights->propal->creer)
{
Expand Down
16 changes: 4 additions & 12 deletions htdocs/comm/propal/note.php
Expand Up @@ -44,23 +44,15 @@
$object = new Propal($db);



/******************************************************************************/
/* Actions */
/******************************************************************************/

if ($action == 'setnote_public' && $user->rights->propale->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) dol_print_error($db,$object->error);
}
$permission=$user->rights->propale->creer; // Used by the include of actions_setnotes.inc.php

include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

else if ($action == 'setnote_private' && $user->rights->propale->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES),'_private');
if ($result < 0) dol_print_error($db,$object->error);
}


/******************************************************************************/
Expand Down
22 changes: 7 additions & 15 deletions htdocs/commande/fiche.php
Expand Up @@ -93,14 +93,18 @@
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('ordercard'));

$permissionnote=$user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php

/******************************************************************************/
/* Actions */
/******************************************************************************/

/*
* Actions
*/

$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks

include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->commande->creer)
{
Expand Down Expand Up @@ -552,18 +556,6 @@
$result = $object->set_remise_absolue($user, GETPOST('remise_absolue'));
}

else if ($action == 'setnote_public' && $user->rights->commande->creer)
{
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) dol_print_error($db,$object->error);
}

else if ($action == 'setnote_private' && $user->rights->commande->creer)
{
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES), '_private');
if ($result < 0) dol_print_error($db,$object->error);
}

// Add a new line
else if ($action == 'addline' && $user->rights->commande->creer)
{
Expand Down
15 changes: 3 additions & 12 deletions htdocs/commande/note.php
Expand Up @@ -50,24 +50,15 @@
dol_print_error($db);
}

$permissionnote=$user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php


/*
* Actions
*/

if ($action == 'setnote_public' && $user->rights->commande->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) dol_print_error($db,$object->error);
}
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

else if ($action == 'setnote_private' && $user->rights->commande->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES),'_private');
if ($result < 0) dol_print_error($db,$object->error);
}

/*
* View
Expand Down
29 changes: 11 additions & 18 deletions htdocs/compta/deplacement/fiche.php
Expand Up @@ -51,10 +51,15 @@
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('tripsandexpensescard'));

$permissionnote=$user->rights->deplacement->creer; // Used by the include of actions_setnotes.inc.php


/*
* Actions
*/
*/

include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

if ($action == 'validate' && $user->rights->deplacement->creer)
{
$object->fetch($id);
Expand Down Expand Up @@ -231,23 +236,11 @@
$result=$object->setValueFrom('km',GETPOST('km','int'));
if ($result < 0) dol_print_error($db, $object->error);
}
else if ($action == 'setnote_public' && $user->rights->deplacement->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) dol_print_error($db, $object->error);
}
else if ($action == 'setnote_private' && $user->rights->deplacement->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES),'_private');
if ($result < 0) dol_print_error($db, $object->error);
}


/*
* View
*/
*/

llxHeader();

Expand Down Expand Up @@ -301,7 +294,7 @@
print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePublic').'</td>';
print '<td valign="top" colspan="2">';

$doleditor = new DolEditor('note_public', GETPOST('note_public', 'alpha'), 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100);
print $doleditor->Create(1);

Expand All @@ -313,7 +306,7 @@
print '<tr>';
print '<td class="border" valign="top">'.$langs->trans('NotePrivate').'</td>';
print '<td valign="top" colspan="2">';

$doleditor = new DolEditor('note_private', GETPOST('note_private', 'alpha'), 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, 100);
print $doleditor->Create(1);

Expand Down Expand Up @@ -400,7 +393,7 @@

$doleditor = new DolEditor('note_public', $object->note_public, 600, 200, 'dolibarr_notes', 'In', false, true, true, ROWS_8, '100');
print $doleditor->Create(1);

print "</td></tr>";

// Private note
Expand Down Expand Up @@ -437,7 +430,7 @@
if ($action == 'delete')
{
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id,$langs->trans("DeleteTrip"),$langs->trans("ConfirmDeleteTrip"),"confirm_delete");

}

$soc = new Societe($db);
Expand Down
18 changes: 4 additions & 14 deletions htdocs/compta/facture.php
Expand Up @@ -100,6 +100,8 @@
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('invoicecard'));

$permissionnote=$user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php


/*
* Actions
Expand All @@ -108,6 +110,8 @@
$parameters=array('socid'=>$socid);
$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks

include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once


// Action clone object
if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->creer)
Expand Down Expand Up @@ -367,20 +371,6 @@
$object->set_ref_client($_POST['ref_client']);
}

else if ($action == 'setnote_public' && $user->rights->facture->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) dol_print_error($db,$object->error);
}

else if ($action == 'setnote_private' && $user->rights->facture->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES),'_private');
if ($result < 0) dol_print_error($db,$object->error);
}

// Classify to validated
else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->valider)
{
Expand Down
27 changes: 9 additions & 18 deletions htdocs/compta/facture/note.php
Expand Up @@ -45,29 +45,20 @@
$object = new Facture($db);
$object->fetch($id);

$permissionnote=$user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php

/******************************************************************************/
/* Actions */
/******************************************************************************/

if ($action == 'setnote_public' && $user->rights->facture->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) dol_print_error($db,$object->error);
}
/*
* Actions
*/

include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

else if ($action == 'setnote_private' && $user->rights->facture->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES),'_private');
if ($result < 0) dol_print_error($db,$object->error);
}


/******************************************************************************/
/* Affichage fiche */
/******************************************************************************/
/*
* View
*/

llxHeader();

Expand Down
43 changes: 16 additions & 27 deletions htdocs/contact/note.php
Expand Up @@ -41,26 +41,15 @@
$object = new Contact($db);
if ($id > 0) $object->fetch($id);

$permissionnote=$user->rights->societe->creer; // Used by the include of actions_setnotes.inc.php


/*
* Actions
*/

/******************************************************************************/
/* Actions */
/******************************************************************************/
if ($action == 'setnote_public' && $user->rights->societe->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES),'_public');
if ($result < 0) setEventMessage($object->error,'errors');
}
include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once

else if ($action == 'setnote_private' && $user->rights->societe->creer)
{
$object->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES),'_private');
if ($result < 0) setEventMessage($object->error,'errors');
}

/*
* View
Expand Down Expand Up @@ -91,57 +80,57 @@
print '<table class="border" width="100%">';

$linkback = '<a href="'.DOL_URL_ROOT.'/contact/list.php">'.$langs->trans("BackToList").'</a>';

// Ref
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
print $form->showrefnav($object, 'id', $linkback);
print '</td></tr>';

// Name
print '<tr><td width="20%">'.$langs->trans("Lastname").' / '.$langs->trans("Label").'</td><td width="30%">'.$object->lastname.'</td>';
print '<td width="20%">'.$langs->trans("Firstname").'</td><td width="30%">'.$object->firstname.'</td></tr>';

// Company
if (empty($conf->global->SOCIETE_DISABLE_CONTACTS))
{
if ($object->socid > 0)
{
$objsoc = new Societe($db);
$objsoc->fetch($object->socid);

print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">'.$objsoc->getNomUrl(1).'</td></tr>';
}

else
{
print '<tr><td>'.$langs->trans("Company").'</td><td colspan="3">';
print $langs->trans("ContactNotLinkedToCompany");
print '</td></tr>';
}
}

// Civility
print '<tr><td>'.$langs->trans("UserTitle").'</td><td colspan="3">';
print $object->getCivilityLabel();
print '</td></tr>';

// Date To Birth
print '<tr>';
if (! empty($object->birthday))
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';

print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.dol_print_date($object->birthday,"day");

print ' &nbsp; ';
//var_dump($birthdatearray);
$ageyear=convertSecondToTime($now-$object->birthday,'year')-1970;
$agemonth=convertSecondToTime($now-$object->birthday,'month')-1;
if ($ageyear >= 2) print '('.$ageyear.' '.$langs->trans("DurationYears").')';
else if ($agemonth >= 2) print '('.$agemonth.' '.$langs->trans("DurationMonths").')';
else print '('.$agemonth.' '.$langs->trans("DurationMonth").')';


print ' &nbsp; - &nbsp; ';
if ($object->birthday_alert) print $langs->trans("BirthdayAlertOn");
else print $langs->trans("BirthdayAlertOff");
Expand All @@ -152,7 +141,7 @@
print '<td>'.$langs->trans("DateToBirth").'</td><td colspan="3">'.$langs->trans("Unknown")."</td>";
}
print "</tr>";

print "</table>";

print '<br>';
Expand Down

0 comments on commit 23eb0f3

Please sign in to comment.