فهرست منبع

MMI Options to use select multiple form to search tasks and projects by user

Mathieu Moulin 9 ماه پیش
والد
کامیت
b5091da027
2فایلهای تغییر یافته به همراه77 افزوده شده و 31 حذف شده
  1. 40 17
      htdocs/projet/list.php
  2. 37 14
      htdocs/projet/tasks/list.php

+ 40 - 17
htdocs/projet/list.php

@@ -103,8 +103,8 @@ $search_opp_percent = GETPOST("search_opp_percent", 'alpha');
 $search_opp_amount = GETPOST("search_opp_amount", 'alpha');
 $search_budget_amount = GETPOST("search_budget_amount", 'alpha');
 $search_public = GETPOST("search_public", 'int');
-$search_project_user = GETPOST('search_project_user', 'int');
-$search_project_contact = GETPOST('search_project_contact', 'int');
+$search_project_user = GETPOST('search_project_user', getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE') ?'array:int' :'int');
+$search_project_contact = GETPOST('search_project_contact', getDolGlobalInt('PROJECT_SEARCH_CONTACT_MULTIPLE') ?'array:int' :'int');
 $search_sale = GETPOST('search_sale', 'int');
 $search_usage_opportunity = GETPOST('search_usage_opportunity', 'int');
 $search_usage_task = GETPOST('search_usage_task', 'int');
@@ -509,10 +509,10 @@ $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user AS u ON p.fk_user_creat = u.rowid';
 if ($search_sale > 0) {
 	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid";
 }
-if ($search_project_user > 0) {
+if (!empty($search_project_user)) {
 	$sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp";
 }
-if ($search_project_contact > 0) {
+if (!empty($search_project_contact)) {
 	$sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp_contact";
 }
 
@@ -617,13 +617,23 @@ if ($search_sale > 0) {
 }
 // No check is done on company permission because readability is managed by public status of project and assignement.
 //if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id).") OR (s.rowid IS NULL))";
-if ($search_project_user > 0) {
-	// TODO Replace this with a EXISTS and remove the link to table + DISTINCT
-	$sql .= " AND ecp.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".((int) $search_project_user);
+if (!empty($search_project_user)) {
+	if (is_array($search_project_user)) {
+		$sql .= " AND ecp.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople IN (".implode(',', $search_project_user).")";
+	}
+	elseif ($search_project_user > 0) {
+		// TODO Replace this with a EXISTS and remove the link to table + DISTINCT
+		$sql .= " AND ecp.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".((int) $search_project_user);
+	}
 }
-if ($search_project_contact > 0) {
-	// TODO Replace this with a EXISTS and remove the link to table + DISTINCT
-	$sql .= " AND ecp_contact.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttypeexternal))).") AND ecp_contact.element_id = p.rowid AND ecp_contact.fk_socpeople = ".((int) $search_project_contact);
+if (!empty($search_project_contact)) {
+	if (is_array($search_project_contact)) {
+		$sql .= " AND ecp_contact.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttypeexternal))).") AND ecp_contact.element_id = p.rowid AND ecp_contact.fk_socpeople IN (".implode(',', $search_project_contact).")";
+	}
+	elseif ($search_project_contact > 0) {
+		// TODO Replace this with a EXISTS and remove the link to table + DISTINCT
+		$sql .= " AND ecp_contact.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttypeexternal))).") AND ecp_contact.element_id = p.rowid AND ecp_contact.fk_socpeople = ".((int) $search_project_contact);
+	}
 }
 if ($search_opp_amount != '') {
 	$sql .= natural_search('p.opp_amount', $search_opp_amount, 1);
@@ -775,6 +785,7 @@ $sql .= $db->order($sortfield, $sortorder);
 if ($limit) {
 	$sql .= $db->plimit($limit + 1, $offset);
 }
+//echo '<pre>'.$sql.'</pre>'; die();
 
 $resql = $db->query($sql);
 if (!$resql) {
@@ -961,11 +972,23 @@ if ($search_opp_percent != '') {
 if ($search_public != '') {
 	$param .= '&search_public='.urlencode($search_public);
 }
-if ($search_project_user > 0) {
-	$param .= '&search_project_user='.urlencode($search_project_user);
+if (!empty($search_project_user)) {
+	if (is_array($search_project_user)) {
+		foreach($search_project_user as $uid)
+			$param .= '&search_project_user[]='.urlencode($uid);
+	}
+	elseif ($search_project_user > 0) {
+		$param .= '&search_project_user='.urlencode($search_project_user);
+	}
 }
-if ($search_project_contact > 0) {
-	$param .= '&search_project_contact='.urlencode($search_project_contact);
+if (!empty($search_project_contact)) {
+	if (is_array($search_project_contact)) {
+		foreach($search_project_contact as $uid)
+			$param .= '&search_project_contact[]='.urlencode($uid);
+	}
+	elseif ($search_project_contact > 0) {
+		$param .= '&search_project_contact='.urlencode($search_project_contact);
+	}
 }
 if ($search_sale > 0) {
 	$param .= '&search_sale='.urlencode($search_sale);
@@ -1106,12 +1129,12 @@ $includeonly = '';
 if (!$user->hasRight('user', 'user', 'lire')) {
 	$includeonly = array($user->id);
 }
-$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_project_user ? $search_project_user : '', 'search_project_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx');
+$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_project_user ? $search_project_user : '', 'search_project_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx', 0, 0, getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE'));
 $moreforfilter .= '</div>';
 
 $moreforfilter .= '<div class="divsearchfield">';
 $tmptitle = $langs->trans('ProjectsWithThisContact');
-$moreforfilter .= img_picto($tmptitle, 'contact', 'class="pictofixedwidth"').$form->selectcontacts(0, $search_project_contact ? $search_project_contact : '', 'search_project_contact', $tmptitle, '', '', 0, 'maxwidth300 widthcentpercentminusx');
+$moreforfilter .= img_picto($tmptitle, 'contact', 'class="pictofixedwidth"').$form->selectcontacts(0, $search_project_contact ? $search_project_contact : '', 'search_project_contact', $tmptitle, '', '', 0, 'maxwidth300 widthcentpercentminusx', false, 0, 0, [], '', '', getDolGlobalInt('PROJECT_SEARCH_CONTACT_MULTIPLE'));
 $moreforfilter .= '</div>';
 
 // If the user can view thirdparties other than his'
@@ -1596,7 +1619,7 @@ while ($i < $imaxinloop) {
 						$stringassignedusers .= $c->getNomUrl(-2, '', 0, '', -1, 0, 'valignmiddle'.($ifisrt ? '' : ' notfirst'));
 					}
 					/*} else {
-					 if (get_class($c) == 'User') {
+					//  if (get_class($c) == 'User') {
 					 $stringassignedusers .= $c->getNomUrl(2, '', 0, 0, 24, 1, '', 'valignmiddle'.($ifisrt ? '' : ' notfirst'));
 					 } else {
 					 $stringassignedusers .= $c->getNomUrl(2, '', 0, '', -1, 0, 'valignmiddle'.($ifisrt ? '' : ' notfirst'));

+ 37 - 14
htdocs/projet/tasks/list.php

@@ -64,8 +64,8 @@ $search_task_ref = GETPOST('search_task_ref');
 $search_task_label = GETPOST('search_task_label');
 $search_task_description = GETPOST('search_task_description');
 $search_task_ref_parent = GETPOST('search_task_ref_parent');
-$search_project_user = GETPOST('search_project_user', 'int');
-$search_task_user = GETPOST('search_task_user', 'int');
+$search_project_user = GETPOST('search_project_user', getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE') ?'array:int' :'int');
+$search_task_user = GETPOST('search_task_user', getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE') ?'array:int' :'int');
 $search_task_progress = GETPOST('search_task_progress');
 $search_task_budget_amount = GETPOST('search_task_budget_amount');
 $search_societe = GETPOST('search_societe');
@@ -376,10 +376,10 @@ if (!empty($arrayfields['t.tobill']['checked']) || !empty($arrayfields['t.billed
 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
 	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
 }
-if ($search_project_user > 0) {
+if (!empty($search_project_user)) {
 	$sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp";
 }
-if ($search_task_user > 0) {
+if (!empty($search_task_user)) {
 	$sql .= ", ".MAIN_DB_PREFIX."element_contact as ect";
 }
 $sql .= " WHERE t.fk_projet = p.rowid";
@@ -450,11 +450,22 @@ if ($search_projectstatus >= 0) {
 		$sql .= " AND p.fk_statut = ".((int) $search_projectstatus);
 	}
 }
-if ($search_project_user > 0) {
-	$sql .= " AND ecp.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".((int) $search_project_user);
+if (!empty($search_project_user)) {
+	if (is_array($search_project_user)) {
+		$sql .= " AND ecp.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople IN (".implode(',', $search_project_user).")";
+	}
+	elseif ($search_project_user > 0) {
+		// TODO Replace this with a EXISTS and remove the link to table + DISTINCT
+		$sql .= " AND ecp.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listofprojectcontacttype))).") AND ecp.element_id = p.rowid AND ecp.fk_socpeople = ".((int) $search_project_user);
+	}
 }
-if ($search_task_user > 0) {
-	$sql .= " AND ect.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect.element_id = t.rowid AND ect.fk_socpeople = ".((int) $search_task_user);
+if (!empty($search_task_user)) {
+	if (is_array($search_task_user)) {
+		$sql .= " AND ect.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect.element_id = t.rowid AND ect.fk_socpeople IN (".implode(',', $search_task_user).")";
+	}
+	elseif ($search_task_user > 0) {
+		$sql .= " AND ect.fk_c_type_contact IN (".$db->sanitize(join(',', array_keys($listoftaskcontacttype))).") AND ect.element_id = t.rowid AND ect.fk_socpeople = ".((int) $search_task_user);
+	}
 }
 // Search for tag/category ($searchCategoryProjectList is an array of ID)
 $searchCategoryProjectList = array($search_categ);
@@ -689,11 +700,23 @@ if ($search_projectstatus != '') {
 if ((is_numeric($search_opp_status) && $search_opp_status >= 0) || in_array($search_opp_status, array('all', 'none'))) {
 	$param .= '&search_opp_status='.urlencode($search_opp_status);
 }
-if ($search_project_user != '') {
-	$param .= '&search_project_user='.urlencode($search_project_user);
+if (!empty($search_project_user)) {
+	if (is_array($search_project_user)) {
+		foreach($$search_project_user as $uid)
+			$param .= '&search_project_user[]='.urlencode($uid);
+	}
+	elseif ($search_project_user > 0) {
+		$param .= '&search_project_user='.urlencode($search_project_user);
+	}
 }
-if ($search_task_user > 0) {
-	$param .= '&search_task_user='.urlencode($search_task_user);
+if (!empty($search_task_user)) {
+	if (is_array($search_task_user)) {
+		foreach($$search_task_user as $uid)
+			$param .= '&search_task_user[]='.urlencode($uid);
+	}
+	elseif ($search_task_user > 0) {
+		$param .= '&search_task_user='.urlencode($search_task_user);
+	}
 }
 if ($optioncss != '') {
 	$param .= '&optioncss='.urlencode($optioncss);
@@ -796,7 +819,7 @@ $includeonly = '';
 if (!$user->hasRight('user', 'user', 'lire')) {
 	$includeonly = array($user->id);
 }
-$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_project_user ? $search_project_user : '', 'search_project_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth250');
+$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_project_user ? $search_project_user : '', 'search_project_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth250', 0, 0, getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE'));
 $moreforfilter .= '</div>';
 
 // If the user can view users
@@ -806,7 +829,7 @@ $includeonly = '';
 if (!$user->hasRight('user', 'user', 'lire')) {
 	$includeonly = array($user->id);
 }
-$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_task_user, 'search_task_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth250');
+$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_task_user, 'search_task_user', $tmptitle, '', 0, $includeonly, '', 0, 0, 0, '', 0, '', 'maxwidth250', 0, 0, getDolGlobalInt('PROJECT_SEARCH_USER_MULTIPLE'));
 $moreforfilter .= '</div>';
 
 // Filter on customer categories