Qual: Uniformize code to use new note system.

This commit is contained in:
Laurent Destailleur
2012-03-18 02:01:23 +01:00
parent 9ed46d9892
commit 59bef9caa1
11 changed files with 127 additions and 200 deletions

View File

@@ -1330,7 +1330,7 @@ abstract class CommonObject
}
/**
* Update private note of element
* Update external ref of element
*
* @param string $ref_ext Update field ref_ext
* @return int <0 if KO, >0 if OK
@@ -1376,7 +1376,7 @@ abstract class CommonObject
}
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
// TODO uniformize fields note_private
// TODO uniformize fields to note_private
if ($this->table_element == 'fichinter' || $this->table_element == 'projet' || $this->table_element == 'projet_task')
{
$sql.= " SET note_private = '".$this->db->escape($note)."'";

View File

@@ -75,9 +75,10 @@ class Form
* @param object $object Object
* @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height', 'select:xxx'...)
* @param string $moreparam More param to add on a href URL
* @return string HTML edit field
*/
function editfieldkey($text,$htmlname,$preselected,$object,$perm,$typeofdata='string')
function editfieldkey($text, $htmlname, $preselected, $object, $perm, $typeofdata='string', $moreparam='')
{
global $conf,$langs;
@@ -103,7 +104,7 @@ class Form
$ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
$ret.=$langs->trans($text);
$ret.='</td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;id='.$object->id.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&amp;id='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
$ret.='</tr></table>';
}
@@ -118,17 +119,14 @@ class Form
* @param string $value Value to show/edit
* @param object $object Object
* @param boolean $perm Permission to allow button to edit parameter
<<<<<<< HEAD
* @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea:rows:cols', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:1:rows:cols', 'select:xxx'...)
=======
* @param string $typeofdata Type of data ('string' by default, 'email', 'numeric:99', 'text' or 'textarea', 'day' or 'datepicker', 'ckeditor:dolibarr_zzz:width:height:1', 'select:xxx'...)
>>>>>>> branch 'develop' of ssh://git@github.com/Dolibarr/dolibarr.git
* @param string $editvalue When in edit mode, use this value as $value instead of value
* @param object $extObject External object
* @param string $success Success message
* @param string $moreparam More param to add on a href URL
* @return string HTML edit field
*/
function editfieldval($text,$htmlname,$value,$object,$perm,$typeofdata='string',$editvalue='',$extObject=null,$success=null)
function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata='string', $editvalue='', $extObject=null, $success=null, $moreparam='')
{
global $conf,$langs,$db;
@@ -145,7 +143,7 @@ class Form
if (GETPOST('action') == 'edit'.$htmlname)
{
$ret.="\n";
$ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
$ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].($moreparam?'?'.$moreparam:'').'">';
$ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
$ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$ret.='<input type="hidden" name="id" value="'.$object->id.'">';

View File

@@ -74,7 +74,7 @@ function project_prepare_head($object)
$head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
$head[$h][1] = $langs->trans('Notes');
$head[$h][2] = 'note';
$head[$h][2] = 'notes';
$h++;
// Then tab for sub level of projet, i mean tasks
@@ -113,17 +113,17 @@ function task_prepare_head($object)
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'task';
$head[$h][2] = 'task_task';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
$head[$h][1] = $langs->trans("TaskRessourceLinks");
$head[$h][2] = 'contact';
$head[$h][2] = 'task_contact';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
$head[$h][1] = $langs->trans("TimeSpent");
$head[$h][2] = 'time';
$head[$h][2] = 'task_time';
$h++;
// Show more tabs from modules
@@ -138,12 +138,12 @@ function task_prepare_head($object)
$listoffiles=dol_dir_list($filesdir,'files',1);
$head[$h][1] = (count($listoffiles)?$langs->trans('DocumentsNb',count($listoffiles)):$langs->trans('Documents'));*/
$head[$h][1] = $langs->trans('Documents');
$head[$h][2] = 'document';
$head[$h][2] = 'task_document';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
$head[$h][1] = $langs->trans('Notes');
$head[$h][2] = 'note';
$head[$h][2] = 'task_notes';
$h++;
return $head;

View File

@@ -19,12 +19,16 @@
$module = $object->element;
$note_public = 'note_public';
$note_private = 'note';
$colwidth=(empty($colwidth)?25:$colwidth);
$permission=$user->rights->$module->creer;
$colwidth=(isset($colwidth)?$colwidth:25);
$permission=(isset($permission)?$permission:$user->rights->$module->creer); // If already defined by caller page
$moreparam=(isset($moreparam)?$moreparam:'');
// Special cases
if ($module == 'propal') { $module = 'propale'; }
elseif ($module == 'fichinter') { $module = 'ficheinter'; $note_private = 'note_private'; }
if ($module == 'propal') { $permission=$user->rights->propale->creer; }
elseif ($module == 'fichinter') { $permission=$user->rights->ficheinter->creer; $note_private = 'note_private'; }
elseif ($module == 'project') { $note_private = 'note_private'; }
elseif ($module == 'project_task') { $note_private = 'note_private'; }
elseif ($module == 'invoice_supplier') { $permission=$user->rights->fournisseur->facture->creer; }
elseif ($module == 'order_supplier') { $permission=$user->rights->fournisseur->commande->creer; }
@@ -35,13 +39,13 @@ else $typeofdata='textarea:12:100';
<!-- BEGIN PHP TEMPLATE NOTES -->
<div class="table-border">
<div class="table-border-row">
<div class="table-key-border-col"<?php echo ' style="width: '.$colwidth.'%"'; ?>><?php echo $form->editfieldkey("NotePublic",$note_public,$object->note_public,$object,$permission,$typeofdata); ?></div>
<div class="table-val-border-col"><?php echo $form->editfieldval("NotePublic",$note_public,$object->note_public,$object,$permission,$typeofdata); ?></div>
<div class="table-key-border-col"<?php echo ' style="width: '.$colwidth.'%"'; ?>><?php echo $form->editfieldkey("NotePublic", $note_public, $object->note_public, $object, $permission, $typeofdata, $moreparam); ?></div>
<div class="table-val-border-col"><?php echo $form->editfieldval("NotePublic", $note_public, $object->note_public, $object, $permission, $typeofdata, '', null, null, $moreparam); ?></div>
</div>
<?php if (! $user->societe_id) { ?>
<div class="table-border-row">
<div class="table-key-border-col"<?php echo ' style="width: '.$colwidth.'%"'; ?>><?php echo $form->editfieldkey("NotePrivate",$note_private,$object->note_private,$object,$permission,$typeofdata); ?></div>
<div class="table-val-border-col"><?php echo $form->editfieldval("NotePrivate",$note_private,$object->note_private,$object,$permission,$typeofdata); ?></div>
<div class="table-key-border-col"<?php echo ' style="width: '.$colwidth.'%"'; ?>><?php echo $form->editfieldkey("NotePrivate", $note_private, $object->note_private, $object, $permission, $typeofdata, $moreparam); ?></div>
<div class="table-val-border-col"><?php echo $form->editfieldval("NotePrivate", $note_private, $object->note_private, $object, $permission, $typeofdata, '', null, null, $moreparam); ?></div>
</div>
<?php } ?>
</div>

View File

@@ -91,7 +91,7 @@ if ($id > 0 || ! empty($ref))
include(DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php');
print '</div>';
dol_fiche_end();
}
}

View File

@@ -113,7 +113,7 @@ if ($id > 0 || ! empty($ref))
//print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
$head = project_prepare_head($project);
dol_fiche_head($head, 'note', $langs->trans('Project'), 0, ($project->public?'projectpub':'project'));
dol_fiche_head($head, 'notes', $langs->trans('Project'), 0, ($project->public?'projectpub':'project'));
print '<table class="border" width="100%">';

View File

@@ -199,7 +199,7 @@ if ($id > 0 || ! empty($ref))
dol_htmloutput_mesg($mesg);
$head = task_prepare_head($task);
dol_fiche_head($head, 'contact', $langs->trans("Task"), 0, 'projecttask');
dol_fiche_head($head, 'task_contact', $langs->trans("Task"), 0, 'projecttask');
/*

View File

@@ -187,7 +187,7 @@ if ($id > 0 || ! empty($ref))
}
$head = task_prepare_head($task);
dol_fiche_head($head, 'document', $langs->trans("Task"), 0, 'projecttask');
dol_fiche_head($head, 'task_document', $langs->trans("Task"), 0, 'projecttask');
$param=(GETPOST('withproject')?'&withproject=1':'');
$linkback=GETPOST('withproject')?'<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$project->id.'">'.$langs->trans("BackToList").'</a>':'';

View File

@@ -32,7 +32,7 @@ $action=GETPOST('action');
$mine = $_REQUEST['mode']=='mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
$id = GETPOST('id','int');
$ref= GETPOST('ref');
$ref= GETPOST('ref', 'alpha');
$withproject=GETPOST('withproject');
// Security check
@@ -41,49 +41,26 @@ if ($user->societe_id > 0) $socid = $user->societe_id;
if (!$user->rights->projet->lire) accessforbidden();
//$result = restrictedArea($user, 'projet', $id, '', 'task'); // TODO ameliorer la verification
$object = new Task($db);
$object->fetch($id, $ref);
/******************************************************************************/
/* Actions */
/******************************************************************************/
/*
* Actions
*/
if ($action == 'update_public' && $user->rights->projet->creer)
if ($action == 'setnote_public' && $user->rights->ficheinter->creer)
{
$task = new Task($db);
$task->fetch($id);
$db->begin();
$res=$task->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
if ($res < 0)
{
$mesg='<div class="error">'.$task->error.'</div>';
$db->rollback();
}
else
{
$db->commit();
}
$result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
if ($result < 0) dol_print_error($db,$object->error);
}
if ($action == 'update_private' && $user->rights->projet->creer)
else if ($action == 'setnote_private' && $user->rights->ficheinter->creer)
{
$task = new Task($db);
$task->fetch($id);
$result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES));
if ($result < 0) dol_print_error($db,$object->error);
}
$db->begin();
$res=$task->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES));
if ($res < 0)
{
$mesg='<div class="error">'.$task->error.'</div>';
$db->rollback();
}
else
{
$db->commit();
}
}
/*
@@ -94,16 +71,13 @@ llxHeader();
$form = new Form($db);
$project = new Project($db);
$task = new Task($db);
$userstatic = new User($db);
$now=dol_now();
if ($id > 0 || ! empty($ref))
{
if ($task->fetch($id, $ref) > 0)
{
$result=$project->fetch($task->fk_project);
$result=$project->fetch($object->fk_project);
if (! empty($project->socid)) $project->societe->fetch($project->socid);
$userWrite = $project->restrictedProjectArea($user,'write');
@@ -158,8 +132,8 @@ if ($id > 0 || ! empty($ref))
print '<br>';
}
$head = task_prepare_head($task);
dol_fiche_head($head, 'note', $langs->trans('Task'), 0, 'projecttask');
$head = task_prepare_head($object);
dol_fiche_head($head, 'task_notes', $langs->trans('Task'), 0, 'projecttask');
print '<table class="border" width="100%">';
@@ -171,14 +145,14 @@ if ($id > 0 || ! empty($ref))
if (! GETPOST('withproject') || empty($project->id))
{
$projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1);
$task->next_prev_filter=" fk_projet in (".$projectsListId.")";
$object->next_prev_filter=" fk_projet in (".$projectsListId.")";
}
else $task->next_prev_filter=" fk_projet = ".$project->id;
print $form->showrefnav($task,'id',$linkback,1,'rowid','ref','',$param);
else $object->next_prev_filter=" fk_projet = ".$project->id;
print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param);
print '</td></tr>';
// Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$task->label.'</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$object->label.'</td></tr>';
// Project
if (empty($withproject))
@@ -194,65 +168,16 @@ if ($id > 0 || ! empty($ref))
print '</td></tr>';
}
// Note public
print '<tr><td valign="top">'.$langs->trans("NotePublic").'</td>';
print '<td valign="top" colspan="3">';
if ($action == 'edit')
{
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update_public">';
print '<textarea name="note_public" cols="80" rows="8">'.$task->note_public."</textarea><br>";
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '</form>';
}
else
{
print ($task->note_public?nl2br($task->note_public):"&nbsp;");
}
print "</td></tr>";
// Note private
if (! $user->societe_id)
{
print '<tr><td valign="top">'.$langs->trans("NotePrivate").'</td>';
print '<td valign="top" colspan="3">';
if ($_GET["action"] == 'edit')
{
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="update_private">';
print '<textarea name="note_private" cols="80" rows="8">'.$task->note_private."</textarea><br>";
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '</form>';
}
else
{
print ($task->note_private?nl2br($task->note_private):"&nbsp;");
}
print "</td></tr>";
}
print "</table>";
print '<br>';
$colwidth=30;
$permission=($user->rights->projet->creer || $user->rights->projet->all->creer);
$moreparam=$param;
include(DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php');
dol_fiche_end();
/*
* Actions
*/
print '<div class="tabsAction">';
if (($user->rights->projet->creer || $user->rights->projet->all->creer) && $_GET['action'] <> 'edit')
{
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$task->id.'&amp;action=edit">'.$langs->trans('Modify').'</a>';
}
else
{
print '<a class="butActionRefused" href="#" title="'.$langs->trans("NotOwnerOfProject").'">'.$langs->trans('Modify').'</a>';
}
print '</div>';
}
}
llxFooter();

View File

@@ -208,7 +208,7 @@ if ($taskid)
dol_htmloutput_mesg($mesg);
$head=task_prepare_head($task);
dol_fiche_head($head, 'task', $langs->trans("Task"),0,'projecttask');
dol_fiche_head($head, 'task_task', $langs->trans("Task"),0,'projecttask');
if ($action == 'edit' && $user->rights->projet->creer)
{

View File

@@ -216,7 +216,7 @@ if ($id > 0 || ! empty($ref))
}
$head=task_prepare_head($task);
dol_fiche_head($head, 'time', $langs->trans("Task"),0,'projecttask');
dol_fiche_head($head, 'task_time', $langs->trans("Task"),0,'projecttask');
dol_htmloutput_mesg($mesg);