/** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone * @param int $option1 1=Copy content, 0=Forget content * @param int $option2 Not used * @return int New id of clone */ function createFromClone($fromid, $option1, $option2) { global $user, $langs; $error = 0; $object = new Mailing($this->db); $object->context['createfromclone'] = 'createfromclone'; $this->db->begin(); // Load source object $object->fetch($fromid); $object->id = 0; $object->statut = 0; // Clear fields $object->titre = $langs->trans("CopyOf") . ' ' . $object->titre . ' ' . dol_print_date(dol_now()); // If no option copy content if (empty($option1)) { // Clear values $object->nbemail = 0; $object->sujet = ''; $object->body = ''; $object->bgcolor = ''; $object->bgimage = ''; $object->email_from = ''; $object->email_replyto = ''; $object->email_errorsto = ''; $object->user_creat = $user->id; $object->user_valid = ''; $object->date_creat = ''; $object->date_valid = ''; $object->date_envoi = ''; } // Create clone $result = $object->create($user); // Other options if ($result < 0) { $this->error = $object->error; $error++; } if (!$error) { //Clone target if (!empty($option2)) { require_once DOL_DOCUMENT_ROOT . '/core/modules/mailings/modules_mailings.php'; $mailing_target = new MailingTargets($this->db); $target_array = array(); $sql = "SELECT fk_contact, "; $sql .= " lastname, "; $sql .= " firstname,"; $sql .= " email,"; $sql .= " other,"; $sql .= " source_url,"; $sql .= " source_id ,"; $sql .= " source_type "; $sql .= " FROM " . MAIN_DB_PREFIX . "mailing_cibles "; $sql .= " WHERE fk_mailing = " . $fromid; dol_syslog(get_class($this) . "::createFromClone", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { if ($this->db->num_rows($result)) { while ($obj = $this->db->fetch_object($result)) { $target_array[] = array('fk_contact' => $obj->fk_contact, 'lastname' => $obj->lastname, 'firstname' => $obj->firstname, 'email' => $obj->email, 'other' => $obj->other, 'source_url' => $obj->source_url, 'source_id' => $obj->source_id, 'source_type' => $obj->source_type); } } } else { $this->error = $this->db->lasterror(); return -1; } $mailing_target->add_to_target($object->id, $target_array); } } unset($object->context['createfromclone']); // End if (!$error) { $this->db->commit(); return $object->id; } else { $this->db->rollback(); return -1; } }
/** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone * @param int $option1 1=Copy content, 0=Forget content * @param int $option2 Not used * @return int New id of clone */ function createFromClone($fromid, $option1, $option2) { global $user, $langs; $error = 0; $object = new Mailing($this->db); $this->db->begin(); // Load source object $object->fetch($fromid); $object->id = 0; $object->statut = 0; // Clear fields $object->titre = $langs->trans("CopyOf") . ' ' . $object->titre . ' ' . dol_print_date(dol_now()); // If no option copy content if (empty($option1)) { // Clear values $object->nbemail = 0; $object->sujet = ''; $object->body = ''; $object->bgcolor = ''; $object->bgimage = ''; $object->email_from = ''; $object->email_replyto = ''; $object->email_errorsto = ''; $object->user_creat = $user->id; $object->user_valid = ''; $object->date_creat = ''; $object->date_valid = ''; $object->date_envoi = ''; } // Create clone $result = $object->create($user); // Other options if ($result < 0) { $this->error = $object->error; $error++; } if (!$error) { } // End if (!$error) { $this->db->commit(); return $object->id; } else { $this->db->rollback(); return -1; } }
$mil->email_from = trim($_POST["from"]); $mil->email_replyto = trim($_POST["replyto"]); $mil->email_errorsto = trim($_POST["errorsto"]); $mil->titre = trim($_POST["titre"]); $mil->sujet = trim($_POST["sujet"]); $mil->body = trim($_POST["body"]); $mil->bgcolor = trim($_POST["bgcolor"]); $mil->bgimage = trim($_POST["bgimage"]); if (! $mil->titre) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTitle")); if (! $mil->sujet) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailTopic")); if (! $mil->body) $message.=($message?'<br>':'').$langs->trans("ErrorFieldRequired",$langs->trans("MailBody")); if (! $message) { if ($mil->create($user) >= 0) { Header("Location: fiche.php?id=".$mil->id); exit; } $message=$mil->error; } $message='<div class="error">'.$message.'</div>'; $_GET["action"]="create"; } // Action update description of emailing if ($_REQUEST["action"] == 'setdesc' || $_REQUEST["action"] == 'setfrom' || $_REQUEST["action"] == 'setreplyto' || $_REQUEST["action"] == 'seterrorsto') { $mil = new Mailing($db);