From 053cfac2629f3e15e5f5befec97498344d07b500 Mon Sep 17 00:00:00 2001 From: Gauthier Date: Mon, 8 Jun 2015 12:39:25 +0200 Subject: [PATCH 1/2] NEW : clone action on agenda events --- htdocs/comm/action/card.php | 54 ++++++++++++++++-- htdocs/comm/action/class/actioncomm.class.php | 57 +++++++++++++++++++ htdocs/langs/en_US/agenda.lang | 4 +- htdocs/langs/fr_FR/agenda.lang | 2 + 4 files changed, 111 insertions(+), 6 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 8dce1b39df0..16e7efe05a3 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -36,6 +36,7 @@ require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; @@ -56,6 +57,7 @@ $backtopage=GETPOST('backtopage','alpha'); $contactid=GETPOST('contactid','int'); $origin=GETPOST('origin','alpha'); $originid=GETPOST('originid','int'); +$confirm = GETPOST('confirm', 'alpha'); $fulldayevent=GETPOST('fullday'); $datep=dol_mktime($fulldayevent?'00':GETPOST("aphour"), $fulldayevent?'00':GETPOST("apmin"), 0, GETPOST("apmonth"), GETPOST("apday"), GETPOST("apyear")); @@ -76,6 +78,10 @@ $object = new ActionComm($db); $contact = new Contact($db); $extrafields = new ExtraFields($db); +$form = new Form($db); +$formfile = new FormFile($db); +$formactions = new FormActions($db); + // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); @@ -127,6 +133,29 @@ if (GETPOST('addassignedtouser') || GETPOST('updateassignedtouser')) if ($action == 'update') $action = 'edit'; } +// Action clone object +if ($action == 'confirm_clone' && $confirm == 'yes') +{ + if (1 == 0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) + { + setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors'); + } + else + { + if ($id > 0) { + $object->fetch($id); + $result = $object->createFromClone(GETPOST('fk_userowner'), GETPOST('socid')); + if ($result > 0) { + header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $result); + exit(); + } else { + setEventMessage($object->error, 'errors'); + $action = ''; + } + } + } +} + // Add event if ($action == 'add') { @@ -540,10 +569,6 @@ if ($action == 'mupdate') $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda'; llxHeader('',$langs->trans("Agenda"),$help_url); -$form = new Form($db); -$formfile = new FormFile($db); -$formactions = new FormActions($db); - if ($action == 'create') { $contact = new Contact($db); @@ -1027,6 +1052,15 @@ if ($id > 0) { dol_fiche_head($head, 'card', $langs->trans("Action"),0,'action'); + + // Clone event + if($action == 'clone') + { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . GETPOST('id'), $langs->trans('CloneAction'), $langs->trans('ConfirmCloneAction', $object->label), 'confirm_clone', $formquestion, 'yes', 1); + + print $formconfirm; + } + // Affichage fiche action en mode visu print ''; @@ -1233,7 +1267,17 @@ if ($id > 0) { print '
'.$langs->trans("Modify").'
'; } - + + if ($user->rights->agenda->allactions->create || + (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->create)) + { + print '
'.$langs->trans("ToClone").'
'; + } + else + { + print '
'.$langs->trans("ToClone").'
'; + } + if ($user->rights->agenda->allactions->delete || (($object->authorid == $user->id || $object->userownerid == $user->id) && $user->rights->agenda->myactions->delete)) { diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index bda4362bed9..f7f1a273221 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -373,6 +373,63 @@ class ActionComm extends CommonObject } + /** + * Load an object from its id and create a new one in database + * + * @param int $socid Id of thirdparty + * @return int New id of clone + */ + function createFromClone() + { + global $db, $user,$langs,$conf,$hookmanager; + + $this->context['createfromclone']='createfromclone'; + + $error=0; + $now=dol_now(); + + $this->db->begin(); + + // Load source object + $objFrom = dol_clone($this); + $this->id=0; + + // Create clone + $result=$this->add($user); + if ($result < 0) $error++; + + if (! $error) + { + // Hook of thirdparty module + if (is_object($hookmanager)) + { + $parameters=array('objFrom'=>$objFrom); + $action=''; + $reshook=$hookmanager->executeHooks('createFrom',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) $error++; + } + + // Call trigger + $result=$this->call_trigger('ACTION_CLONE',$user); + if ($result < 0) { $error++; } + // End call triggers + } + + unset($this->context['createfromclone']); + + // End + if (! $error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + /** * Load object from database * diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index 3a3f24e2dc1..8967f180608 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -95,4 +95,6 @@ WorkingDaysRange=Working days range AddEvent=Create event MyAvailability=My availability ActionType=Event type -DateActionBegin=Start event date \ No newline at end of file +DateActionBegin=Start event date +CloneAction=Clone event +ConfirmClonePropal=Are you sure you want to clone the event %s ? \ No newline at end of file diff --git a/htdocs/langs/fr_FR/agenda.lang b/htdocs/langs/fr_FR/agenda.lang index bd4709d1649..3290a930d37 100644 --- a/htdocs/langs/fr_FR/agenda.lang +++ b/htdocs/langs/fr_FR/agenda.lang @@ -96,3 +96,5 @@ AddEvent=Créer un événement MyAvailability=Ma disponibilité ActionType=Type événement DateActionBegin=Date début événément +CloneAction=Cloner événement +ConfirmCloneAction=Êtes-vous sûr de vouloir cloner l'événement %s ? \ No newline at end of file From dd81d3a76219b4baaf4258fc4c38667e254ec859 Mon Sep 17 00:00:00 2001 From: Gauthier Date: Mon, 8 Jun 2015 15:06:43 +0200 Subject: [PATCH 2/2] NEW : add all assigned users and all extrafields data in new event when we createFromClone --- htdocs/comm/action/class/actioncomm.class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index f7f1a273221..b7d13f218d0 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -392,6 +392,10 @@ class ActionComm extends CommonObject // Load source object $objFrom = dol_clone($this); + + $this->fetch_optionals(); + $this->fetch_userassigned(); + $this->id=0; // Create clone