add: quick link categories to project

This commit is contained in:
Theo 2021-10-22 15:48:39 +02:00
parent d54423990d
commit 29f847c13a
3 changed files with 233 additions and 1 deletions

View File

@ -173,7 +173,8 @@ if ($elemid && $action == 'addintocategory' &&
(($type == Categorie::TYPE_PRODUCT && ($user->rights->produit->creer || $user->rights->service->creer)) ||
($type == Categorie::TYPE_CUSTOMER && $user->rights->societe->creer) ||
($type == Categorie::TYPE_SUPPLIER && $user->rights->societe->creer) ||
($type == Categorie::TYPE_TICKET && $user->rights->ticket->write)
($type == Categorie::TYPE_TICKET && $user->rights->ticket->write) ||
($type == Categorie::TYPE_PROJECT && $user->rights->projet->creer)
)) {
if ($type == Categorie::TYPE_PRODUCT) {
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
@ -191,6 +192,10 @@ if ($elemid && $action == 'addintocategory' &&
require_once DOL_DOCUMENT_ROOT.'/ticket/class/ticket.class.php';
$newobject = new Ticket($db);
$elementtype = 'ticket';
} elseif ($type == Categorie::TYPE_PROJECT) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
$newobject = new Project($db);
$elementtype = 'project';
}
$result = $newobject->fetch($elemid);
@ -874,6 +879,26 @@ if ($type == Categorie::TYPE_PROJECT) {
if ($objects < 0) {
dol_print_error($db, $object->error, $object->errors);
} else {
// Form to add record into a category
$showclassifyform = 1;
if ($showclassifyform) {
print '<br>';
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="typeid" value="'.$typeid.'">';
print '<input type="hidden" name="type" value="'.$typeid.'">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="action" value="addintocategory">';
print '<table class="noborder centpercent">';
print '<tr class="liste_titre"><td>';
print $langs->trans("AddProjectIntoCategory").' &nbsp;';
$form->selectProjects('', 'elemid');
print '<input type="submit" class="button buttongen" value="'.$langs->trans("ClassifyInCategory").'"></td>';
print '</tr>';
print '</table>';
print '</form>';
}
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="typeid" value="'.$typeid.'">';

View File

@ -6838,6 +6838,212 @@ class Form
$optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtypem);
}
/**
* Return list of tickets in Ajax if Ajax activated or go to selectTicketsList
*
* @param int $selected Preselected tickets
* @param string $htmlname Name of HTML select field (must be unique in page).
* @param string $filtertype To add a filter
* @param int $limit Limit on number of returned lines
* @param int $status Ticket status
* @param string $selected_input_value Value of preselected input text (for use with ajax)
* @param int $hidelabel Hide label (0=no, 1=yes, 2=show search icon (before) and placeholder, 3 search icon after)
* @param array $ajaxoptions Options for ajax_autocompleter
* @param int $socid Thirdparty Id (to get also price dedicated to this customer)
* @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text.
* @param int $forcecombo Force to use combo box
* @param string $morecss Add more css on select
* @param array $selected_combinations Selected combinations. Format: array([attrid] => attrval, [...])
* @param string $nooutput No print, return the output into a string
* @return void|string
*/
public function selectProjects($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 0, $status = 1, $selected_input_value = '', $hidelabel = 0, $ajaxoptions = array(), $socid = 0, $showempty = '1', $forcecombo = 0, $morecss = '', $selected_combinations = null, $nooutput = 0)
{
global $langs, $conf;
$out = '';
// check parameters
if (is_null($ajaxoptions)) $ajaxoptions = array();
if (!empty($conf->use_javascript_ajax) && !empty($conf->global->TICKET_USE_SEARCH_TO_SELECT)) {
$placeholder = '';
if ($selected && empty($selected_input_value)) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
$projecttmpselect = new Project($this->db);
$projecttmpselect->fetch($selected);
$selected_input_value = $projecttmpselect->ref;
unset($projecttmpselect);
}
$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/projet/ajax/projects.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
if (empty($hidelabel)) $out .= $langs->trans("RefOrLabel").' : ';
elseif ($hidelabel > 1) {
$placeholder = ' placeholder="'.$langs->trans("RefOrLabel").'"';
if ($hidelabel == 2) {
$out .= img_picto($langs->trans("Search"), 'search');
}
}
$out .= '<input type="text" class="minwidth100" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' '.(!empty($conf->global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />';
if ($hidelabel == 3) {
$out .= img_picto($langs->trans("Search"), 'search');
}
} else {
$out .= $this->selectProjectsList($selected, $htmlname, $filtertype, $limit, $status, 0, $socid, $showempty, $forcecombo, $morecss);
}
if (empty($nooutput)) print $out;
else return $out;
}
/**
* Return list of projects.
* Called by selectProjects.
*
* @param int $selected Preselected project
* @param string $htmlname Name of select html
* @param string $filtertype Filter on project type
* @param int $limit Limit on number of returned lines
* @param string $filterkey Filter on project ref or subject
* @param int $status Ticket status
* @param int $outputmode 0=HTML select string, 1=Array
* @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text.
* @param int $forcecombo Force to use combo box
* @param string $morecss Add more css on select
* @return array Array of keys for json
*/
public function selectProjectsList($selected = '', $htmlname = 'projectid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '')
{
global $langs, $conf, $user, $db;
$out = '';
$outarray = array();
$selectFields = " p.rowid, p.ref";
$sql = "SELECT ";
$sql .= $selectFields;
$sql .= " FROM ".MAIN_DB_PREFIX."projet as p";
$sql .= ' WHERE p.entity IN ('.getEntity('project').')';
// Add criteria on ref/label
if ($filterkey != '') {
$sql .= ' AND (';
$prefix = empty($conf->global->TICKET_DONOTSEARCH_ANYWHERE) ? '%' : ''; // Can use index if PRODUCT_DONOTSEARCH_ANYWHERE is on
// For natural search
$scrit = explode(' ', $filterkey);
$i = 0;
if (count($scrit) > 1) $sql .= "(";
foreach ($scrit as $crit) {
if ($i > 0) $sql .= " AND ";
$sql .= "p.ref LIKE '".$this->db->escape($prefix.$crit)."%'";
$sql .= "";
$i++;
}
if (count($scrit) > 1) $sql .= ")";
$sql .= ')';
}
$sql .= $this->db->plimit($limit, 0);
// Build output string
dol_syslog(get_class($this)."::selectProjectsList search projects", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
$num = $this->db->num_rows($result);
$events = null;
if (!$forcecombo) {
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$out .= ajax_combobox($htmlname, $events, $conf->global->PROJECT_USE_SEARCH_TO_SELECT);
}
$out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
$textifempty = '';
// Do not use textifempty = ' ' or '&nbsp;' here, or search on key will search on ' key'.
//if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty='';
if (!empty($conf->global->PROJECT_USE_SEARCH_TO_SELECT)) {
if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
else $textifempty .= $langs->trans("All");
} else {
if ($showempty && !is_numeric($showempty)) $textifempty = $langs->trans($showempty);
}
if ($showempty) $out .= '<option value="0" selected>'.$textifempty.'</option>';
$i = 0;
while ($num && $i < $num) {
$opt = '';
$optJson = array();
$objp = $this->db->fetch_object($result);
$this->constructProjectListOption($objp, $opt, $optJson, $selected, $filterkey);
// Add new entry
// "key" value of json key array is used by jQuery automatically as selected value
// "label" value of json key array is used by jQuery automatically as text for combo box
$out .= $opt;
array_push($outarray, $optJson);
$i++;
}
$out .= '</select>';
$this->db->free($result);
if (empty($outputmode)) return $out;
return $outarray;
} else {
dol_print_error($db);
}
}
/**
* constructTicketListOption.
* This define value for &$opt and &$optJson.
*
* @param resource $objp Result set of fetch
* @param string $opt Option (var used for returned value in string option format)
* @param string $optJson Option (var used for returned value in json format)
* @param string $selected Preselected value
* @param string $filterkey Filter key to highlight
* @return void
*/
protected function constructProjectListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '')
{
global $langs, $conf, $user, $db;
$outkey = '';
$outval = '';
$outref = '';
$outlabel = '';
$outtype = '';
$label = $objp->label;
$outkey = $objp->rowid;
$outref = $objp->ref;
$outlabel = $objp->label;
$outtype = $objp->fk_product_type;
$opt = '<option value="'.$objp->rowid.'"';
$opt .= ($objp->rowid == $selected) ? ' selected' : '';
$opt .= '>';
$opt .= $objp->ref;
$objRef = $objp->ref;
if (!empty($filterkey) && $filterkey != '') $objRef = preg_replace('/('.preg_quote($filterkey, '/').')/i', '<strong>$1</strong>', $objRef, 1);
$outval .= $objRef;
$opt .= "</option>\n";
$optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtypem);
}
/**
* Generic method to select a component from a combo list.

View File

@ -89,6 +89,7 @@ CategorieRecursiv=Lier automatiquement avec le(a) tag/catégorie parent(e)
CategorieRecursivHelp=Si l'option est activé, quand un produit est ajouté dans une sous-catégorie, le produit sera ajouté aussi dans la catégorie parente.
AddProductServiceIntoCategory=Ajouter le produit/service suivant
AddCustomerIntoCategory=Assigner cette catégorie au client
AddProjectIntoCategory=Assigner cette catégorie au projet
AddTicketIntoCategory=Assigner cette catégorie au ticket
AddSupplierIntoCategory=Assigner cette catégorie au fournisseur
ShowCategory=Afficher tag/catégorie