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 * @param string $ref_ext Update field ref_ext
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
@@ -1376,7 +1376,7 @@ abstract class CommonObject
} }
$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $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') if ($this->table_element == 'fichinter' || $this->table_element == 'projet' || $this->table_element == 'projet_task')
{ {
$sql.= " SET note_private = '".$this->db->escape($note)."'"; $sql.= " SET note_private = '".$this->db->escape($note)."'";

View File

@@ -75,9 +75,10 @@ class Form
* @param object $object Object * @param object $object Object
* @param boolean $perm Permission to allow button to edit parameter * @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 $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 * @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; global $conf,$langs;
@@ -103,7 +104,7 @@ class Form
$ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">'; $ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
$ret.=$langs->trans($text); $ret.=$langs->trans($text);
$ret.='</td>'; $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>'; $ret.='</tr></table>';
} }
@@ -118,17 +119,14 @@ class Form
* @param string $value Value to show/edit * @param string $value Value to show/edit
* @param object $object Object * @param object $object Object
* @param boolean $perm Permission to allow button to edit parameter * @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: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 string $editvalue When in edit mode, use this value as $value instead of value
* @param object $extObject External object * @param object $extObject External object
* @param string $success Success message * @param string $success Success message
* @param string $moreparam More param to add on a href URL
* @return string HTML edit field * @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; global $conf,$langs,$db;
@@ -145,7 +143,7 @@ class Form
if (GETPOST('action') == 'edit'.$htmlname) if (GETPOST('action') == 'edit'.$htmlname)
{ {
$ret.="\n"; $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="action" value="set'.$htmlname.'">';
$ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; $ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$ret.='<input type="hidden" name="id" value="'.$object->id.'">'; $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][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
$head[$h][1] = $langs->trans('Notes'); $head[$h][1] = $langs->trans('Notes');
$head[$h][2] = 'note'; $head[$h][2] = 'notes';
$h++; $h++;
// Then tab for sub level of projet, i mean tasks // 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][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');;
$head[$h][1] = $langs->trans("Card"); $head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'task'; $head[$h][2] = 'task_task';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');; $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][1] = $langs->trans("TaskRessourceLinks");
$head[$h][2] = 'contact'; $head[$h][2] = 'task_contact';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');; $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][1] = $langs->trans("TimeSpent");
$head[$h][2] = 'time'; $head[$h][2] = 'task_time';
$h++; $h++;
// Show more tabs from modules // Show more tabs from modules
@@ -138,12 +138,12 @@ function task_prepare_head($object)
$listoffiles=dol_dir_list($filesdir,'files',1); $listoffiles=dol_dir_list($filesdir,'files',1);
$head[$h][1] = (count($listoffiles)?$langs->trans('DocumentsNb',count($listoffiles)):$langs->trans('Documents'));*/ $head[$h][1] = (count($listoffiles)?$langs->trans('DocumentsNb',count($listoffiles)):$langs->trans('Documents'));*/
$head[$h][1] = $langs->trans('Documents'); $head[$h][1] = $langs->trans('Documents');
$head[$h][2] = 'document'; $head[$h][2] = 'task_document';
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');; $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][1] = $langs->trans('Notes');
$head[$h][2] = 'note'; $head[$h][2] = 'task_notes';
$h++; $h++;
return $head; return $head;

View File

@@ -19,12 +19,16 @@
$module = $object->element; $module = $object->element;
$note_public = 'note_public'; $note_public = 'note_public';
$note_private = 'note'; $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 // Special cases
if ($module == 'propal') { $module = 'propale'; } if ($module == 'propal') { $permission=$user->rights->propale->creer; }
elseif ($module == 'fichinter') { $module = 'ficheinter'; $note_private = 'note_private'; } 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 == 'invoice_supplier') { $permission=$user->rights->fournisseur->facture->creer; }
elseif ($module == 'order_supplier') { $permission=$user->rights->fournisseur->commande->creer; } elseif ($module == 'order_supplier') { $permission=$user->rights->fournisseur->commande->creer; }
@@ -35,13 +39,13 @@ else $typeofdata='textarea:12:100';
<!-- BEGIN PHP TEMPLATE NOTES --> <!-- BEGIN PHP TEMPLATE NOTES -->
<div class="table-border"> <div class="table-border">
<div class="table-border-row"> <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-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); ?></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> </div>
<?php if (! $user->societe_id) { ?> <?php if (! $user->societe_id) { ?>
<div class="table-border-row"> <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-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); ?></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> </div>
<?php } ?> <?php } ?>
</div> </div>

View File

@@ -91,7 +91,7 @@ if ($id > 0 || ! empty($ref))
include(DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'); 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; //print "userAccess=".$userAccess." userWrite=".$userWrite." userDelete=".$userDelete;
$head = project_prepare_head($project); $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%">'; print '<table class="border" width="100%">';

View File

@@ -199,7 +199,7 @@ if ($id > 0 || ! empty($ref))
dol_htmloutput_mesg($mesg); dol_htmloutput_mesg($mesg);
$head = task_prepare_head($task); $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); $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':''); $param=(GETPOST('withproject')?'&withproject=1':'');
$linkback=GETPOST('withproject')?'<a href="'.DOL_URL_ROOT.'/projet/tasks.php?id='.$project->id.'">'.$langs->trans("BackToList").'</a>':''; $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; $mine = $_REQUEST['mode']=='mine' ? 1 : 0;
//if (! $user->rights->projet->all->lire) $mine=1; // Special for projects //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects
$id = GETPOST('id','int'); $id = GETPOST('id','int');
$ref= GETPOST('ref'); $ref= GETPOST('ref', 'alpha');
$withproject=GETPOST('withproject'); $withproject=GETPOST('withproject');
// Security check // Security check
@@ -41,51 +41,28 @@ if ($user->societe_id > 0) $socid = $user->societe_id;
if (!$user->rights->projet->lire) accessforbidden(); if (!$user->rights->projet->lire) accessforbidden();
//$result = restrictedArea($user, 'projet', $id, '', 'task'); // TODO ameliorer la verification //$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); $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
$task->fetch($id); if ($result < 0) dol_print_error($db,$object->error);
$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();
}
} }
if ($action == 'update_private' && $user->rights->projet->creer) else if ($action == 'setnote_private' && $user->rights->ficheinter->creer)
{ {
$task = new Task($db); $result=$object->update_note(dol_html_entity_decode(GETPOST('note_private'), ENT_QUOTES));
$task->fetch($id); 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();
}
} }
/* /*
* View * View
*/ */
@@ -94,16 +71,13 @@ llxHeader();
$form = new Form($db); $form = new Form($db);
$project = new Project($db); $project = new Project($db);
$task = new Task($db);
$userstatic = new User($db); $userstatic = new User($db);
$now=dol_now(); $now=dol_now();
if ($id > 0 || ! empty($ref)) if ($id > 0 || ! empty($ref))
{ {
if ($task->fetch($id, $ref) > 0) $result=$project->fetch($object->fk_project);
{
$result=$project->fetch($task->fk_project);
if (! empty($project->socid)) $project->societe->fetch($project->socid); if (! empty($project->socid)) $project->societe->fetch($project->socid);
$userWrite = $project->restrictedProjectArea($user,'write'); $userWrite = $project->restrictedProjectArea($user,'write');
@@ -158,8 +132,8 @@ if ($id > 0 || ! empty($ref))
print '<br>'; print '<br>';
} }
$head = task_prepare_head($task); $head = task_prepare_head($object);
dol_fiche_head($head, 'note', $langs->trans('Task'), 0, 'projecttask'); dol_fiche_head($head, 'task_notes', $langs->trans('Task'), 0, 'projecttask');
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@@ -171,14 +145,14 @@ if ($id > 0 || ! empty($ref))
if (! GETPOST('withproject') || empty($project->id)) if (! GETPOST('withproject') || empty($project->id))
{ {
$projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,1); $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; else $object->next_prev_filter=" fk_projet = ".$project->id;
print $form->showrefnav($task,'id',$linkback,1,'rowid','ref','',$param); print $form->showrefnav($object,'id',$linkback,1,'rowid','ref','',$param);
print '</td></tr>'; print '</td></tr>';
// Label // 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 // Project
if (empty($withproject)) if (empty($withproject))
@@ -194,65 +168,16 @@ if ($id > 0 || ! empty($ref))
print '</td></tr>'; 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 "</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(); 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(); llxFooter();

View File

@@ -208,7 +208,7 @@ if ($taskid)
dol_htmloutput_mesg($mesg); dol_htmloutput_mesg($mesg);
$head=task_prepare_head($task); $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) if ($action == 'edit' && $user->rights->projet->creer)
{ {

View File

@@ -216,7 +216,7 @@ if ($id > 0 || ! empty($ref))
} }
$head=task_prepare_head($task); $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); dol_htmloutput_mesg($mesg);