diff --git a/htdocs/admin/ticket.php b/htdocs/admin/ticket.php index 4f87131c145d6..6ca2430157555 100644 --- a/htdocs/admin/ticket.php +++ b/htdocs/admin/ticket.php @@ -45,7 +45,7 @@ $modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php $label = GETPOST('label', 'alpha'); -$scandir = GETPOST('scandir', 'alpha'); +$scandir = GETPOST('scan_dir', 'alpha'); $type = 'ticket'; $error = 0; diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index d87123a97c946..fe38f2fd650c3 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -501,7 +501,7 @@ public function get_substitutionarray_other($outputlangs) * Define array with couple substitution key => substitution value * Note that vars into substitutions array are formatted. * - * @param Object $object Main object to use as data source + * @param CommonObject $object Main object to use as data source * @param Translate $outputlangs Lang object to use for output * @param string $array_key Name of the key for return array * @return array Array of substitution @@ -515,6 +515,7 @@ public function get_substitutionarray_object($object, $outputlangs, $array_key = $already_payed_all = 0; if ($object->element == 'facture') { + /** @var Facture $object */ $invoice_source = new Facture($this->db); if ($object->fk_facture_source > 0) { $invoice_source->fetch($object->fk_facture_source); @@ -528,7 +529,7 @@ public function get_substitutionarray_object($object, $outputlangs, $array_key = $date = (isset($object->element) && $object->element == 'contrat' && isset($object->date_contrat)) ? $object->date_contrat : (isset($object->date) ? $object->date : null); if (get_class($object) == 'CommandeFournisseur') { - /* @var $object CommandeFournisseur*/ + /** @var CommandeFournisseur $object*/ $object->date_validation = $object->date_valid; $object->date_commande = $object->date; } @@ -703,7 +704,7 @@ public function get_substitutionarray_object($object, $outputlangs, $array_key = * Define array with couple substitution key => substitution value * Note that vars into substitutions array are formatted. * - * @param Object $line Object line + * @param CommonObjectLine $line Object line * @param Translate $outputlangs Lang object to use for output * @param int $linenumber The number of the line for the substitution of "object_line_pos" * @return array Return a substitution array @@ -927,8 +928,6 @@ public function get_substitutionarray_each_var_object(&$object, $outputlangs, $r } } - //var_dump($array_other); - return $array_other; } diff --git a/htdocs/core/modules/modTicket.class.php b/htdocs/core/modules/modTicket.class.php index c4539befe3f34..260022ef63ab3 100644 --- a/htdocs/core/modules/modTicket.class.php +++ b/htdocs/core/modules/modTicket.class.php @@ -376,7 +376,7 @@ public function init($options = '') //ODT template $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/tickets/template_ticket.odt'; $dirodt = DOL_DATA_ROOT.'/doctemplates/tickets'; - $dest = $dirodt.'/template_order.odt'; + $dest = $dirodt.'/template_ticket.odt'; if (file_exists($src) && !file_exists($dest)) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -394,8 +394,10 @@ public function init($options = '') array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110121, 'ticket', 'internal', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1), array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110122, 'ticket', 'external', 'SUPPORTCLI', 'Contact client suivi incident', 1);", "ignoreerror" => 1), array("sql" => "insert into llx_c_type_contact(rowid, element, source, code, libelle, active ) values (110123, 'ticket', 'external', 'CONTRIBUTOR', 'Intervenant', 1);", "ignoreerror" => 1), + // remove old settings "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = 'TICKET_ADDON_PDF_ODT_PATH' AND type = 'ticket' AND entity = ".((int) $conf->entity), - "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('TICKET_ADDON_PDF_ODT_PATH','ticket',".((int) $conf->entity).")" + // activate default odt templates + array("sql" =>"INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, libelle, entity, description) VALUES('generic_ticket_odt','ticket','ODT templates',".((int) $conf->entity).",'TICKET_ADDON_PDF_ODT_PATH');", "ignoreerror" =>1), ); return $this->_init($sql, $options); diff --git a/htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php b/htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php index 6904febfe28cb..f7d5c828d6a04 100644 --- a/htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php +++ b/htdocs/core/modules/ticket/doc/doc_generic_ticket_odt.modules.php @@ -322,7 +322,7 @@ public function write_file($object, $outputlangs, $srctemplatepath, $hidedetails } // Make substitutions into odt - $array_user = $this->get_substitutionarray_user($object, $outputlangs); + $array_user = $this->get_substitutionarray_user($user, $outputlangs); $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); $array_other = $this->get_substitutionarray_other($outputlangs); diff --git a/htdocs/ticket/card.php b/htdocs/ticket/card.php index 8c8441d14153f..7dfa3e69baf54 100644 --- a/htdocs/ticket/card.php +++ b/htdocs/ticket/card.php @@ -31,6 +31,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/ticket/class/actions_ticket.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formticket.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/ticket.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -707,7 +708,6 @@ // Actions to build doc include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; - //var_dump($action);exit; // Actions to send emails $triggersendname = 'TICKET_SENTBYMAIL'; @@ -729,6 +729,7 @@ $userstat = new User($db); $form = new Form($db); +$formfile = new FormFile($db); $formticket = new FormTicket($db); if (isModEnabled('project')) { $formproject = new FormProjets($db); @@ -811,8 +812,7 @@ print $form->buttonsSaveCancel(); print ''; */ -} elseif (empty($action) || $action == 'view' || $action == 'addlink' || $action == 'dellink' || $action == 'presend' || $action == 'presend_addmessage' || $action == 'close' || $action == 'abandon' || $action == 'delete' || $action == 'editcustomer' || $action == 'progression' || $action == 'categories' || $action == 'reopen' - || $action== 'edit_contrat' || $action == 'editsubject' || $action == 'edit_extras' || $action == 'update_extras' || $action == 'edit_extrafields' || $action == 'set_extrafields' || $action == 'classify' || $action == 'sel_contract' || $action == 'edit_message_init' || $action == 'set_status' || $action == 'dellink') { +} elseif (empty($action) || in_array($action, ['builddoc', 'view', 'addlink', 'dellink', 'presend', 'presend_addmessage', 'close', 'abandon', 'delete', 'editcustomer', 'progression', 'categories', 'reopen', 'edit_contrat', 'editsubject', 'edit_extras', 'update_extras', 'edit_extrafields', 'set_extrafields', 'classify', 'sel_contract', 'edit_message_init', 'set_status', 'dellink'])) { if ($res > 0) { // or for unauthorized internals users if (!$user->socid && (getDolGlobalString('TICKET_LIMIT_VIEW_ASSIGNED_ONLY') && $object->fk_user_assign != $user->id) && !$user->hasRight('ticket', 'manage')) { @@ -1613,6 +1613,16 @@ if ($action != 'presend' && $action != 'presend_addmessage' && $action != 'add_message') { print '
'; print ''; // ancre + /* + * Generated documents + */ + $filename = dol_sanitizeFileName($object->ref); + $filedir = $upload_dir."/".dol_sanitizeFileName($object->ref); + $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id; + $genallowed = $permissiontoadd; + $delallowed = $permissiontodelete; + + print $formfile->showdocuments('ticket', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', $thirdparty->default_lang); // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('ticket')); diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index b17e0f26286e3..c797c7c65d890 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -344,7 +344,9 @@ class Ticket extends CommonObject 'email_date' => array('type'=>'datetime', 'label'=>'EmailDate', 'visible'=>-2, 'enabled'=>1, 'position'=>541), 'progress' => array('type'=>'integer', 'label'=>'Progression', 'visible'=>-1, 'enabled'=>1, 'position'=>540, 'notnull'=>-1, 'css'=>'right', 'help'=>"", 'isameasure'=>2, 'csslist'=>'width50'), 'resolution' => array('type'=>'integer', 'label'=>'Resolution', 'visible'=>-1, 'enabled'=>'getDolGlobalString("TICKET_ENABLE_RESOLUTION")', 'position'=>550, 'notnull'=>1), - 'fk_statut' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>600, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0 => 'Unread', 1 => 'Read', 3 => 'Answered', 4 => 'Assigned', 5 => 'InProgress', 6 => 'Waiting', 8 => 'SolvedClosed', 9 => 'Deleted')), + 'model_pdf' =>array('type'=>'varchar(255)', 'label'=>'PDFTemplate', 'enabled'=>1, 'visible'=>0, 'position'=>560), + 'extraparams' =>array('type'=>'varchar(255)', 'label'=>'Extraparams', 'enabled'=>1, 'visible'=>-1, 'position'=>570), + 'fk_statut' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>600, 'notnull'=>1, 'index'=>1, 'arrayofkeyval'=>array(0 => 'Unread', 1 => 'Read', 3 => 'TicketAnswered', 4 => 'Assigned', 5 => 'InProgress', 6 => 'Waiting', 8 => 'SolvedClosed', 9 => 'Deleted')), 'import_key' =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'position'=>900), ); // END MODULEBUILDER PROPERTIES @@ -526,6 +528,7 @@ public function create($user, $notrigger = 0) $sql .= "date_close,"; $sql .= "entity,"; $sql .= "notify_tiers_at_create,"; + $sql .= "model_pdf,"; $sql .= "ip"; $sql .= ") VALUES ("; $sql .= " ".(!isset($this->ref) ? '' : "'".$this->db->escape($this->ref)."'").","; @@ -552,6 +555,7 @@ public function create($user, $notrigger = 0) $sql .= " ".(!isset($this->date_close) || dol_strlen($this->date_close) == 0 ? 'NULL' : "'".$this->db->idate($this->date_close)."'"); $sql .= ", ".((int) $this->entity); $sql .= ", ".(!isset($this->notify_tiers_at_create) ? '1' : "'".$this->db->escape($this->notify_tiers_at_create)."'"); + $sql .= ", '".$this->db->escape($this->model_pdf)."'"; $sql .= ", ".(!isset($this->ip) ? 'NULL' : "'".$this->db->escape($this->ip)."'"); $sql .= ")"; @@ -665,6 +669,8 @@ public function fetch($id = 0, $ref = '', $track_id = '', $email_msgid = '') $sql .= " t.date_last_msg_sent,"; $sql .= " t.date_close,"; $sql .= " t.tms,"; + $sql .= " t.model_pdf,"; + $sql .= " t.extraparams,"; $sql .= " t.ip,"; $sql .= " type.label as type_label, category.label as category_label, severity.label as severity_label"; $sql .= " FROM ".MAIN_DB_PREFIX."ticket as t"; @@ -706,6 +712,8 @@ public function fetch($id = 0, $ref = '', $track_id = '', $email_msgid = '') $this->email_date = $this->db->jdate($obj->email_date); $this->subject = $obj->subject; $this->message = $obj->message; + $this->model_pdf = $obj->model_pdf; + $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams, true) : array(); $this->ip = $obj->ip; $this->status = $obj->status; @@ -1022,7 +1030,9 @@ public function update($user, $notrigger = 0) if (isset($this->severity_code)) { $this->timing = trim($this->severity_code); } - + if (isset($this->model_pdf)) { + $this->model_pdf = trim($this->model_pdf); + } // Check parameters // Put here code to add a control on parameters values // Update request @@ -1047,6 +1057,7 @@ public function update($user, $notrigger = 0) $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql .= " date_read=".(dol_strlen($this->date_read) != 0 ? "'".$this->db->idate($this->date_read)."'" : 'null').","; $sql .= " date_last_msg_sent=".(dol_strlen($this->date_last_msg_sent) != 0 ? "'".$this->db->idate($this->date_last_msg_sent)."'" : 'null').","; + $sql .= " model_pdf=".(isset($this->model_pdf) ? "'".$this->db->escape($this->model_pdf)."'" : "null").","; $sql .= " date_close=".(dol_strlen($this->date_close) != 0 ? "'".$this->db->idate($this->date_close)."'" : 'null'); $sql .= " WHERE rowid=".((int) $this->id); @@ -2600,9 +2611,6 @@ public function newMessage($user, &$action, $private = 1, $public_area = 0) if (!$error && $id > 0) { setEventMessages($langs->trans('TicketMessageSuccessfullyAdded'), null, 'mesgs'); - //var_dump($_SESSION); - //var_dump($listofpaths);exit; - if (!empty($public_area)) { /* * Message created from the Public interface @@ -3142,6 +3150,40 @@ public function getKanbanView($option = '', $arraydata = null) $return .= '
'; $return .= '
'; $return .= ''; + return $return; } + + /** + * Create a document onto disk according to template module. + * + * @param string $modele Force template to use ('' to not force) + * @param Translate $outputlangs object lang a utiliser pour traduction + * @param int $hidedetails Hide details of lines + * @param int $hidedesc Hide description + * @param int $hideref Hide ref + * @param null|array $moreparams Array to provide more information + * @return int 0 if KO, 1 if OK + */ + public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) + { + global $langs; + + $langs->load("ticket"); + $outputlangs->load("ticket"); + + if (!dol_strlen($modele)) { + $modele = 'generic_ticket_odt'; + + if (!empty($this->model_pdf)) { + $modele = $this->model_pdf; + } elseif (getDolGlobalString('TICKET_ADDON_PDF')) { + $modele = getDolGlobalString('TICKET_ADDON_PDF'); + } + } + + $modelpath = "core/modules/ticket/doc/"; + + return $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); + } }