Fix: Works with checkbox htdocs/core/class/html.form.class.php

This commit is contained in:
Laurent Destailleur 2012-05-07 17:04:35 +02:00
parent d5f0c487ad
commit 792c0a33f3
6 changed files with 63 additions and 121 deletions

View File

@ -2254,7 +2254,10 @@ class Form
if ($inputarray.length>0) {
$.each($inputarray, function() {
var inputname = this;
var inputvalue = $("#" + this).val();
var more = \'\';
if ($("#" + this).attr("type") == \'checkbox\') { more = \':checked\'; }
var inputvalue = $("#" + this + more).val();
if (typeof inputvalue == \'undefined\') { inputvalue=\'\'; }
options += \'&\' + inputname + \'=\' + inputvalue;
});
//alert(options);

View File

@ -85,7 +85,11 @@ TaskIsNotAffectedToYou=Task not allocated to you
ErrorTimeSpentIsEmpty=Time spent is empty
ThisWillAlsoRemoveTasks=This action will also delete all tasks of project (<b>%s</b> tasks at the moment) and all inputs of time spent.
IfNeedToUseOhterObjectKeepEmpty=If some objects (invoice, order, ...), belonging to another third party, must be linked to the project to create, keep this empty to have the project being multi third parties.
CloneProject=Clone project (associated task will be duplicated too)
CloneProject=Clone project
CloneTasks=Clone tasks
CloneContacts=Clone contacts
CloneNotes=Clone notes
CloneFiles=Clone joined files
ConfirmCloneProject=Are you sure to clone this project ?
ProjectReportDate=Change task date according project start date
ErrorShiftTaskDate=Impossible to shift task date according to new project start date

View File

@ -85,7 +85,11 @@ TaskIsNotAffectedToYou=Tâche qui ne vous est pas affectée
ErrorTimeSpentIsEmpty=Le temps consommé n'est pas renseigné
ThisWillAlsoRemoveTasks=Cette opération détruira également les tâches du projet (<b>%s</b> tâches actuellement) et le suivi des consommés.
IfNeedToUseOhterObjectKeepEmpty=Si des objets (facture, commande, ...), appartenant à un autre tiers que celui choisi, doivent être liés au projet à créer, laisser vide afin de laisser le projet multi-tiers.
CloneProject=Cloner le projet (les taches associées sont dupliquées également)
CloneProject=Cloner le projet
CloneTasks=Cloner les taches
CloneContacts=Cloner les contacts
CloneNotes=Cloner les notes
CloneFiles=Cloner les pièces jointes
ConfirmCloneProject=Êtes-vous sûr de vouloir cloner ce projet ?
ProjectReportDate=Reporter les dates des taches en fonction de la date de départ.
ErrorShiftTaskDate=Une erreur c'est produite dans le report des dates des taches.

View File

@ -883,21 +883,24 @@ class Project extends CommonObject
return $projects;
}
/** Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
* @param bool $clone_contact clone contact of project
* @param bool $clone_task clone task of project
* @param bool $clone_file clone file of project
* @param bool $clone_note clone note of project
* @return int New id of clone
*/
function createFromClone($fromid,$clone_contact=false,$clone_task=true,$clone_file=true,$clone_note=true)
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
* @param bool $clone_contact clone contact of project
* @param bool $clone_task clone task of project
* @param bool $clone_file clone file of project
* @param bool $clone_note clone note of project
* @return int New id of clone
*/
function createFromClone($fromid,$clone_contact=false,$clone_task=true,$clone_file=false,$clone_note=true)
{
global $user,$langs,$conf;
$error=0;
dol_syslog("createFromClone clone_contact=".$clone_contact." clone_task=".$clone_task." clone_file=".$clone_file." clone_note=".$clone_note);
$now = dol_mktime(0,0,0,idate('m',dol_now()),idate('d',dol_now()),idate('Y',dol_now()));
$clone_project=new Project($this->db);
@ -908,30 +911,18 @@ class Project extends CommonObject
$clone_project->fetch($fromid);
$orign_dt_start=$clone_project->date_start;
$orign_project_ref=$clone_project->ref;
$clone_project->id=0;
$clone_project->date_start = $now;
if (!(empty($clone_project->date_end)))
{
//Calculate new project end date ragarding difference between original project start date and new start date (now)
$datetime_start = new DateTime();
$datetime_start->setTimestamp($orign_dt_start);
$datetime_now = new DateTime();
$datetime_now->setTimestamp($now);
$diff_dt = $datetime_start->diff($datetime_now);
$datetime_end = new DateTime();
$datetime_end->setTimestamp($clone_project->date_end);
$datetime_end->add($diff_dt);
$clone_project->date_end = $datetime_end->getTimestamp();
$clone_project->date_end = $clone_project->date_end + ($now - $orign_dt_start);
}
$clone_project->datec = $now;
if (!$clone_note)
if (! $clone_note)
{
$clone_project->note_private='';
$clone_project->note_public='';
@ -1139,11 +1130,12 @@ class Project extends CommonObject
}
/** Shift project task date from current date to delta
*
* @param timestamp $old_project_dt_start old project start date
* @return int 1 if OK or < 0 if KO
*/
/**
* Shift project task date from current date to delta
*
* @param timestamp $old_project_dt_start old project start date
* @return int 1 if OK or < 0 if KO
*/
function shiftTaskDate($old_project_dt_start)
{
global $user,$langs,$conf;
@ -1156,11 +1148,6 @@ class Project extends CommonObject
$socid=0;
if ($user->societe_id > 0) $socid = $user->societe_id;
//convert timestamp to datetime
$old_project_dt_st = new DateTime();
$old_project_dt_st->setTimestamp($old_project_dt_start);
$old_project_dt_st->setTime(0,0,0); //Use 00:00:00 as time to be sure to not have side
$tasksarray=$taskstatic->getTasksArray(0, 0, $this->id, $socid, 0);
foreach ($tasksarray as $tasktoshiftdate)
@ -1183,39 +1170,13 @@ class Project extends CommonObject
//Calcultate new task start date with difference between old proj start date and origin task start date
if (!empty($tasktoshiftdate->date_start))
{
dol_syslog(get_class($this)."::shiftTaskDate to_update", LOG_DEBUG);
$orign_task_datetime_start = new DateTime();
$orign_task_datetime_start->setTimestamp($tasktoshiftdate->date_start);
$orign_task_datetime_start->setTime(0,0,0); //Use 00:00:00 as time to be sure to not have side effect
$diff_dt_st = $old_project_dt_st->diff($orign_task_datetime_start);
//Project new start date
$datetime_start = new DateTime();
$datetime_start->setTimestamp($this->date_start);
$datetime_start->setTime(0,0,0); //Use 00:00:00 as time to be sure to not have side
//New task start date
$datetime_start->add($diff_dt_st);
$task->date_start = $datetime_start->getTimestamp();
$task->date_start = $this->date_start + ($tasktoshiftdate->date_start - $old_project_dt_st);
}
//Calcultate new task end date with difference between origin proj end date and origin task end date
if (!empty($tasktoshiftdate->date_end))
{
$orign_task_datetime_end = new DateTime();
$orign_task_datetime_end->setTimestamp($tasktoshiftdate->date_end);
$orign_task_datetime_end->setTime(0,0,0); //Use 00:00:00 as hour to be sure to not have side effect
$diff_dt_end = $old_project_dt_st->diff($orign_task_datetime_end);
//Project new start date
$datetime_end = new DateTime();
$datetime_end->setTimestamp($this->date_start);
$datetime_end->setTime(0,0,0); //Use 00:00:00 as time to be sure to not have side
//New task start date
$datetime_end->add($diff_dt_end);
$task->date_end = $datetime_end->getTimestamp();
$task->date_end = $this->date_start + ($tasktoshiftdate->date_end - $old_project_dt_st);
}
if ($to_update)

View File

@ -957,7 +957,7 @@ class Task extends CommonObject
$now=dol_now();
$datec = dol_mktime(0,0,0,idate('m',$now),idate('d',$now),idate('Y',$now));
$datec = $now;
$clone_task=new Task($this->db);
@ -980,41 +980,18 @@ class Task extends CommonObject
$projectstatic->fetch($ori_project_id);
//Origin project strat date
$orign_project_dt_start = new DateTime();
$orign_project_dt_start->setTimestamp($projectstatic->date_start);
$orign_project_dt_start = $projectstatic->date_start;
//Calcultate new task start date with difference between origin proj start date and origin task start date
if (!empty($clone_task->date_start))
{
$orign_task_datetime_start = new DateTime();
$orign_task_datetime_start->setTimestamp($clone_task->date_start);
$orign_task_datetime_start->setTime(0,0,0); //Use 00:00:00 as hour to be sure to not have side effect
$diff_dt_st = $orign_project_dt_start->diff($orign_task_datetime_start);
//cloned project start date
$datetime_start = new DateTime();
$datetime_start->setTimestamp($now);
//New task start date
$datetime_start->add($diff_dt_st);
$clone_task->date_start = $datetime_start->getTimestamp();
$clone_task->date_start = $now + $clone_task->date_start - $orign_project_dt_start;
}
//Calcultate new task end date with difference between origin proj end date and origin task end date
if (!empty($clone_task->date_end))
{
$orign_task_datetime_end = new DateTime();
$orign_task_datetime_end->setTimestamp($clone_task->date_end);
$orign_task_datetime_end->setTime(0,0,0); //Use 00:00:00 as hour to be sure to not have side effect
$diff_dt_end = $orign_project_dt_start->diff($orign_task_datetime_end);
//cloned project start date
$datetime_end = new DateTime();
$datetime_end->setTimestamp($now);
//New task start date
$datetime_end->add($diff_dt_end);
$clone_task->date_end = $datetime_end->getTimestamp();
$clone_task->date_end = $now + $clone_task->date_end - $orign_project_dt_start;
}
}

View File

@ -303,25 +303,11 @@ if ($action == 'confirm_clone' && $user->rights->projet->creer && GETPOST('confi
$idtoclone=$id;
$project = new Project($db);
$project->fetch($idtoclone);
$result=$project->createFromClone($idtoclone,true,true,true,true);
if ($result <= 0)
{
$mesg='<div class="error">'.$project->error.'</div>';
}
else
{
$id=$result;
$action='edit';
$comefromclone=true;
}
}
if ($action == 'confirm_clone' && $user->rights->projet->creer && GETPOST('confirm') == 'yes')
{
$idtoclone=$id;
$project = new Project($db);
$project->fetch($idtoclone);
$result=$project->createFromClone($idtoclone,true,true,true,true);
$clone_contacts=GETPOST('clone_contacts')?1:0;
$clone_tasks=GETPOST('clone_tasks')?1:0;
$clone_files=GETPOST('clone_files')?1:0;
$clone_notes=GETPOST('clone_notes')?1:0;
$result=$project->createFromClone($idtoclone,$clone_contacts,$clone_tasks,$clone_files,$clone_notes);
if ($result <= 0)
{
$mesg='<div class="error">'.$project->error.'</div>';
@ -482,8 +468,15 @@ else
// Clone confirmation
if ($action == 'clone')
{
$ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$project->id,$langs->trans("CloneProject"),$langs->trans("ConfirmCloneProject"),"confirm_clone",'','',1);
if ($ret == 'html') print '<br>';
$formquestion=array(
'text' => $langs->trans("ConfirmClone"),
array('type' => 'checkbox', 'name' => 'clone_contacts','label' => $langs->trans("CloneContacts"), 'value' => true),
array('type' => 'checkbox', 'name' => 'clone_tasks', 'label' => $langs->trans("CloneTasks"), 'value' => true),
array('type' => 'checkbox', 'name' => 'clone_notes', 'label' => $langs->trans("CloneNotes"), 'value' => true),
array('type' => 'checkbox', 'name' => 'clone_files', 'label' => $langs->trans("CloneFiles"), 'value' => false)
);
print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$project->id, $langs->trans("CloneProject"), $langs->trans("ConfirmCloneProject"), "confirm_clone", $formquestion, '', 1, 240);
}
if ($action == 'edit' && $userWrite > 0)