From 69db790cf5fdd5fa96f9f524eb88a50d9af900fc Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Mon, 8 Jun 2020 14:43:14 +0200 Subject: [PATCH 1/6] NEW multiselect type and date to date filter --- htdocs/core/class/html.form.class.php | 19 +++ htdocs/core/lib/company.lib.php | 161 ++++++++++++++++++-------- 2 files changed, 132 insertions(+), 48 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 289b92f84ae..f3560be0545 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5241,6 +5241,25 @@ class Form print $retstring; return; } + /** + * Show 2 HTML widget to input a date or combo list for day, month, years and optionaly hours and minutes. + * Fields are preselected with : + * - set_time date (must be a local PHP server timestamp or string date with format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM') + * - local date in user area, if set_time is '' (so if set_time is '', output may differs when done from two different location) + * - Empty (fields empty), if set_time is -1 (in this case, parameter empty must also have value 1) + * + * @param integer $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). + * @param integer $set_time_end Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). + * @param string $prefix Prefix for fields name + * @return string Html for selectDate + * @see form_date(), select_month(), select_year(), select_dayofweek() + */ + public function selectDateToDate($set_time = '', $set_time_end = '', $prefix = 're', $empty = 0) { + $ret = $this->selectDate($set_time, $prefix.'_start',0 ,0, $empty); + $ret .='
'; + $ret .=$this->selectDate($set_time_end, $prefix.'_end', 0 ,0, $empty); + return $ret; + } /** * Show a HTML widget to input a date or combo list for day, month, years and optionaly hours and minutes. diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 3f6e8563a50..6e1f87bc962 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1273,7 +1273,27 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin global $form; global $param, $massactionbutton; - + $start_year = GETPOST('dateevent_startyear'); + $start_month = GETPOST('dateevent_startmonth'); + $start_day = GETPOST('dateevent_startday'); + $end_year = GETPOST('dateevent_endyear'); + $end_month = GETPOST('dateevent_endmonth'); + $end_day = GETPOST('dateevent_endday'); + if(!empty($start_year) && !empty($start_month) && !empty($start_day)) { + $search_start = $start_year.'-'.$start_month.'-'.$start_day; + $tms_start = strtotime($search_start); + } + if(!empty($end_year) && !empty($end_month) && !empty($end_day)) { + $search_end = $end_year.'-'.$end_month.'-'.$end_day.' 23:59:59'; + $tms_end = strtotime($search_end); + } + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All test are required to be compatible with all browsers + { + $search_start = ''; + $tms_start = ''; + $search_end = ''; + $tms_end = ''; + } dol_include_once('/comm/action/class/actioncomm.class.php'); // Check parameters @@ -1379,54 +1399,47 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } } - // Condition on actioncode - if (!empty($actioncode)) - { - if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) - { - if ($actioncode == 'AC_NON_AUTO') $sql .= " AND c.type != 'systemauto'"; - elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND c.type = 'systemauto'"; - else { - if ($actioncode == 'AC_OTH') $sql .= " AND c.type != 'systemauto'"; - elseif ($actioncode == 'AC_OTH_AUTO') $sql .= " AND c.type = 'systemauto'"; + if(! empty($search_start) && ! empty($search_end)) { + $sql .= " AND ((a.datep BETWEEN '$search_start' AND '$search_end') OR (a.datep2 BETWEEN '$search_start' AND '$search_end'))"; + } + else if(empty($search_start) && ! empty($search_end)) { + $sql .= " AND ((a.datep <= '$search_end') OR (a.datep2 <= '$search_end'))"; + } + else if(! empty($search_start) && empty($search_end)) { + $sql .= " AND ((a.datep >= '$search_start') OR (a.datep2 >= '$search_start'))"; + } + + if(is_array($actioncode) && ! empty($actioncode)) { + $sql .= ' AND ('; + foreach($actioncode as $key => $code) { + if($key != 0) $sql .= "OR ("; + if(! empty($code)) addEventTypeSQL($sql, $code, $donetodo, $now, $filters, ""); + if($key != 0) $sql .= ")"; + } + $sql .= ')'; + } + else if(! empty($actioncode)) addEventTypeSQL($sql, $actioncode, $donetodo, $now, $filters); + + if(is_array($actioncode)) { + + foreach($actioncode as $code) { + $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj); + if(! empty($sql2)) { + if(! empty($sql)) $sql = $sql." UNION ".$sql2; + else if(empty($sql)) $sql = $sql2; + break; } - } else { - if ($actioncode == 'AC_NON_AUTO') $sql .= " AND c.type != 'systemauto'"; - elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " AND c.type = 'systemauto'"; - else $sql .= " AND c.code = '".$db->escape($actioncode)."'"; } } - if ($donetodo == 'todo') $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))"; - elseif ($donetodo == 'done') $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))"; - if (is_array($filters) && $filters['search_agenda_label']) $sql .= natural_search('a.label', $filters['search_agenda_label']); - } - - // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing. - if (!empty($conf->mailing->enabled) && !empty($objcon->email) - && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) - { - $langs->load("mails"); - - $sql2 = "SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type"; - $sql2 .= ", '' as fk_element, '' as elementtype, '' as contact_id"; - $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto"; - $sql2 .= ", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action - if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql2 .= ", '' as lastname, '' as firstname"; - elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql2 .= ", '' as lastname, '' as firstname"; - elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql2 .= ", '' as ref"; - elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql2 .= ", '' as ref"; - elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql2 .= ", '' as ref"; - $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u"; - $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email. - $sql2 .= " AND mc.statut = 1"; - $sql2 .= " AND u.rowid = m.fk_user_valid"; - $sql2 .= " AND mc.fk_mailing=m.rowid"; - } - - if (!empty($sql) && !empty($sql2)) { - $sql = $sql." UNION ".$sql2; - } elseif (empty($sql) && !empty($sql2)) { - $sql = $sql2; + else { + $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj); + if(! empty($sql) && ! empty($sql2)) { + $sql = $sql." UNION ".$sql2; + } + else if(empty($sql) && ! empty($sql2)) { + $sql = $sql2; + } + } } //TODO Add limit in nb of results @@ -1550,10 +1563,10 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $out .= ''; $out .= ''; $out .= ''; - $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, 0, 1); + $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, !empty($conf->global->AGENDA_USE_MULTISELECT_TYPE) ? 1 : -1, 1); $out .= ''; $out .= ''; - $out .= ''; + $out .= ''.$form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1).''; $out .= ''; $out .= ''; $out .= ''; @@ -1830,3 +1843,55 @@ function show_subsidiaries($conf, $langs, $db, $object) return $i; } + +function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDOR = "AND") { + global $conf, $db; + // Condition on actioncode + + if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) + { + if ($actioncode == 'AC_NON_AUTO') $sql .= " $sqlANDOR c.type != 'systemauto'"; + elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; + else + { + if ($actioncode == 'AC_OTH') $sql .= " $sqlANDOR c.type != 'systemauto'"; + elseif ($actioncode == 'AC_OTH_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; + } + } + else + { + if ($actioncode == 'AC_NON_AUTO') $sql .= " $sqlANDOR c.type != 'systemauto'"; + elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; + else $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'"; + } + + if ($donetodo == 'todo') $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))"; + elseif ($donetodo == 'done') $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))"; + if (is_array($filters) && $filters['search_agenda_label']) $sql .= natural_search('a.label', $filters['search_agenda_label']); +} + +function addMailingEventTypeSQL($actioncode, $objcon, $filterobj) { + global $conf, $langs, $db; + // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing. + if (!empty($conf->mailing->enabled) && !empty($objcon->email) + && (empty($actioncode) || $actioncode == 'AC_OTH_AUTO' || $actioncode == 'AC_EMAILING')) { + $langs->load("mails"); + + $sql2 = "SELECT m.rowid as id, m.titre as label, mc.date_envoi as dp, mc.date_envoi as dp2, '100' as percent, 'mailing' as type"; + $sql2 .= ", '' as fk_element, '' as elementtype, '' as contact_id"; + $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto"; + $sql2 .= ", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action + if(is_object($filterobj) && get_class($filterobj) == 'Societe') $sql2 .= ", '' as lastname, '' as firstname"; + else if(is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql2 .= ", '' as lastname, '' as firstname"; + else if(is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql2 .= ", '' as ref"; + else if(is_object($filterobj) && get_class($filterobj) == 'Product') $sql2 .= ", '' as ref"; + else if(is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql2 .= ", '' as ref"; + $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u"; + $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email. + $sql2 .= " AND mc.statut = 1"; + $sql2 .= " AND u.rowid = m.fk_user_valid"; + $sql2 .= " AND mc.fk_mailing=m.rowid"; + return $sql2; + } + +} From 3dd7c81f54b8b17d4f9c606b161dc81162871c9b Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Mon, 8 Jun 2020 15:58:20 +0200 Subject: [PATCH 2/6] FIX stickler --- htdocs/core/class/html.form.class.php | 10 ++++--- htdocs/core/lib/company.lib.php | 43 +++++++++++++++++++-------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index f3560be0545..76a203ad8df 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5251,13 +5251,15 @@ class Form * @param integer $set_time Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). * @param integer $set_time_end Pre-selected date (must be a local PHP server timestamp), -1 to keep date not preselected, '' to use current date with 00:00 hour (Parameter 'empty' must be 0 or 2). * @param string $prefix Prefix for fields name + * @param string $empty 0=Fields required, 1=Empty inputs are allowed, 2=Empty inputs are allowed for hours only * @return string Html for selectDate * @see form_date(), select_month(), select_year(), select_dayofweek() */ - public function selectDateToDate($set_time = '', $set_time_end = '', $prefix = 're', $empty = 0) { - $ret = $this->selectDate($set_time, $prefix.'_start',0 ,0, $empty); - $ret .='
'; - $ret .=$this->selectDate($set_time_end, $prefix.'_end', 0 ,0, $empty); + public function selectDateToDate($set_time = '', $set_time_end = '', $prefix = 're', $empty = 0) + { + $ret = $this->selectDate($set_time, $prefix.'_start', 0, 0, $empty); + $ret .= '
'; + $ret .= $this->selectDate($set_time_end, $prefix.'_end', 0, 0, $empty); return $ret; } diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 6e1f87bc962..5f7d9f8fccf 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1279,11 +1279,11 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $end_year = GETPOST('dateevent_endyear'); $end_month = GETPOST('dateevent_endmonth'); $end_day = GETPOST('dateevent_endday'); - if(!empty($start_year) && !empty($start_month) && !empty($start_day)) { + if (!empty($start_year) && !empty($start_month) && !empty($start_day)) { $search_start = $start_year.'-'.$start_month.'-'.$start_day; $tms_start = strtotime($search_start); } - if(!empty($end_year) && !empty($end_month) && !empty($end_day)) { + if (!empty($end_year) && !empty($end_month) && !empty($end_day)) { $search_end = $end_year.'-'.$end_month.'-'.$end_day.' 23:59:59'; $tms_end = strtotime($search_end); } @@ -1399,13 +1399,13 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } } - if(! empty($search_start) && ! empty($search_end)) { + if(! empty($search_start) && ! empty($search_end)) { $sql .= " AND ((a.datep BETWEEN '$search_start' AND '$search_end') OR (a.datep2 BETWEEN '$search_start' AND '$search_end'))"; } - else if(empty($search_start) && ! empty($search_end)) { + elseif (empty($search_start) && ! empty($search_end)) { $sql .= " AND ((a.datep <= '$search_end') OR (a.datep2 <= '$search_end'))"; } - else if(! empty($search_start) && empty($search_end)) { + elseif (! empty($search_start) && empty($search_end)) { $sql .= " AND ((a.datep >= '$search_start') OR (a.datep2 >= '$search_start'))"; } @@ -1418,25 +1418,25 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } $sql .= ')'; } - else if(! empty($actioncode)) addEventTypeSQL($sql, $actioncode, $donetodo, $now, $filters); + elseif (! empty($actioncode)) addEventTypeSQL($sql, $actioncode, $donetodo, $now, $filters); if(is_array($actioncode)) { foreach($actioncode as $code) { $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj); - if(! empty($sql2)) { - if(! empty($sql)) $sql = $sql." UNION ".$sql2; - else if(empty($sql)) $sql = $sql2; + if (! empty($sql2)) { + if (! empty($sql)) $sql = $sql." UNION ".$sql2; + elseif (empty($sql)) $sql = $sql2; break; } } } else { $sql2 = addMailingEventTypeSQL($actioncode, $objcon, $filterobj); - if(! empty($sql) && ! empty($sql2)) { + if (! empty($sql) && ! empty($sql2)) { $sql = $sql." UNION ".$sql2; } - else if(empty($sql) && ! empty($sql2)) { + elseif (empty($sql) && ! empty($sql2)) { $sql = $sql2; } } @@ -1843,7 +1843,18 @@ function show_subsidiaries($conf, $langs, $db, $object) return $i; } - +/** + * Add Event Type SQL + * + * @param string $sql $sql modified + * @param string $actioncode Action code + * @param string $donetodo donetodo + * @param string $now now + * @param string $filters array + * @param string $donetodo donetodo + * @param string $sqlANDOR "AND", "OR" or "" + * @return void + */ function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDOR = "AND") { global $conf, $db; // Condition on actioncode @@ -1870,6 +1881,14 @@ function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDO if (is_array($filters) && $filters['search_agenda_label']) $sql .= natural_search('a.label', $filters['search_agenda_label']); } +/** + * Add Mailing Event Type SQL + * + * @param string $actioncode Action code + * @param string $objcon objcon + * @param Object $filterobj + * @return string + */ function addMailingEventTypeSQL($actioncode, $objcon, $filterobj) { global $conf, $langs, $db; // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing. From b4dd11ec98af2a07b62802128133f2228e0affc3 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 8 Jun 2020 14:00:57 +0000 Subject: [PATCH 3/6] Fixing style errors. --- htdocs/core/lib/company.lib.php | 62 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 5f7d9f8fccf..b98a61b451d 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1399,7 +1399,7 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin } } - if(! empty($search_start) && ! empty($search_end)) { + if (! empty($search_start) && ! empty($search_end)) { $sql .= " AND ((a.datep BETWEEN '$search_start' AND '$search_end') OR (a.datep2 BETWEEN '$search_start' AND '$search_end'))"; } elseif (empty($search_start) && ! empty($search_end)) { @@ -1409,20 +1409,19 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $sql .= " AND ((a.datep >= '$search_start') OR (a.datep2 >= '$search_start'))"; } - if(is_array($actioncode) && ! empty($actioncode)) { + if (is_array($actioncode) && ! empty($actioncode)) { $sql .= ' AND ('; - foreach($actioncode as $key => $code) { - if($key != 0) $sql .= "OR ("; - if(! empty($code)) addEventTypeSQL($sql, $code, $donetodo, $now, $filters, ""); - if($key != 0) $sql .= ")"; + foreach ($actioncode as $key => $code) { + if ($key != 0) $sql .= "OR ("; + if (! empty($code)) addEventTypeSQL($sql, $code, $donetodo, $now, $filters, ""); + if ($key != 0) $sql .= ")"; } $sql .= ')'; } elseif (! empty($actioncode)) addEventTypeSQL($sql, $actioncode, $donetodo, $now, $filters); - if(is_array($actioncode)) { - - foreach($actioncode as $code) { + if (is_array($actioncode)) { + foreach ($actioncode as $code) { $sql2 = addMailingEventTypeSQL($code, $objcon, $filterobj); if (! empty($sql2)) { if (! empty($sql)) $sql = $sql." UNION ".$sql2; @@ -1855,26 +1854,25 @@ function show_subsidiaries($conf, $langs, $db, $object) * @param string $sqlANDOR "AND", "OR" or "" * @return void */ -function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDOR = "AND") { +function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDOR = "AND") +{ global $conf, $db; // Condition on actioncode - if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) + if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) { - if ($actioncode == 'AC_NON_AUTO') $sql .= " $sqlANDOR c.type != 'systemauto'"; - elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; - else - { - if ($actioncode == 'AC_OTH') $sql .= " $sqlANDOR c.type != 'systemauto'"; - elseif ($actioncode == 'AC_OTH_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; - } - } - else - { - if ($actioncode == 'AC_NON_AUTO') $sql .= " $sqlANDOR c.type != 'systemauto'"; - elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; - else $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'"; - } + if ($actioncode == 'AC_NON_AUTO') $sql .= " $sqlANDOR c.type != 'systemauto'"; + elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; + else { + if ($actioncode == 'AC_OTH') $sql .= " $sqlANDOR c.type != 'systemauto'"; + elseif ($actioncode == 'AC_OTH_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; + } + } + else { + if ($actioncode == 'AC_NON_AUTO') $sql .= " $sqlANDOR c.type != 'systemauto'"; + elseif ($actioncode == 'AC_ALL_AUTO') $sql .= " $sqlANDOR c.type = 'systemauto'"; + else $sql .= " $sqlANDOR c.code = '".$db->escape($actioncode)."'"; + } if ($donetodo == 'todo') $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))"; elseif ($donetodo == 'done') $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))"; @@ -1889,7 +1887,8 @@ function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDO * @param Object $filterobj * @return string */ -function addMailingEventTypeSQL($actioncode, $objcon, $filterobj) { +function addMailingEventTypeSQL($actioncode, $objcon, $filterobj) +{ global $conf, $langs, $db; // Add also event from emailings. TODO This should be replaced by an automatic event ? May be it's too much for very large emailing. if (!empty($conf->mailing->enabled) && !empty($objcon->email) @@ -1900,11 +1899,11 @@ function addMailingEventTypeSQL($actioncode, $objcon, $filterobj) { $sql2 .= ", '' as fk_element, '' as elementtype, '' as contact_id"; $sql2 .= ", 'AC_EMAILING' as acode, '' as alabel, '' as apicto"; $sql2 .= ", u.rowid as user_id, u.login as user_login, u.photo as user_photo, u.firstname as user_firstname, u.lastname as user_lastname"; // User that valid action - if(is_object($filterobj) && get_class($filterobj) == 'Societe') $sql2 .= ", '' as lastname, '' as firstname"; - else if(is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql2 .= ", '' as lastname, '' as firstname"; - else if(is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql2 .= ", '' as ref"; - else if(is_object($filterobj) && get_class($filterobj) == 'Product') $sql2 .= ", '' as ref"; - else if(is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql2 .= ", '' as ref"; + if (is_object($filterobj) && get_class($filterobj) == 'Societe') $sql2 .= ", '' as lastname, '' as firstname"; + elseif (is_object($filterobj) && get_class($filterobj) == 'Adherent') $sql2 .= ", '' as lastname, '' as firstname"; + elseif (is_object($filterobj) && get_class($filterobj) == 'CommandeFournisseur') $sql2 .= ", '' as ref"; + elseif (is_object($filterobj) && get_class($filterobj) == 'Product') $sql2 .= ", '' as ref"; + elseif (is_object($filterobj) && get_class($filterobj) == 'Ticket') $sql2 .= ", '' as ref"; $sql2 .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."user as u"; $sql2 .= " WHERE mc.email = '".$db->escape($objcon->email)."'"; // Search is done on email. $sql2 .= " AND mc.statut = 1"; @@ -1912,5 +1911,4 @@ function addMailingEventTypeSQL($actioncode, $objcon, $filterobj) { $sql2 .= " AND mc.fk_mailing=m.rowid"; return $sql2; } - } From 012574b487042cfa7ca878f0edc98c408b670b8c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 12 Jun 2020 00:51:19 +0200 Subject: [PATCH 4/6] Update html.form.class.php --- htdocs/core/class/html.form.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 76a203ad8df..d8d43931083 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5241,6 +5241,7 @@ class Form print $retstring; return; } + /** * Show 2 HTML widget to input a date or combo list for day, month, years and optionaly hours and minutes. * Fields are preselected with : From 39651953b3c6048c40ab60adc548d723c9b0b964 Mon Sep 17 00:00:00 2001 From: quentin Date: Wed, 1 Jul 2020 14:04:41 +0200 Subject: [PATCH 5/6] FIX refacto --- htdocs/core/class/html.form.class.php | 2 +- htdocs/core/lib/company.lib.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index ece403b3c51..762a22cc37a 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -5241,7 +5241,7 @@ class Form print $retstring; return; } - + /** * Show 2 HTML widget to input a date or combo list for day, month, years and optionaly hours and minutes. * Fields are preselected with : diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index b98a61b451d..2d58e545b41 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1850,9 +1850,8 @@ function show_subsidiaries($conf, $langs, $db, $object) * @param string $donetodo donetodo * @param string $now now * @param string $filters array - * @param string $donetodo donetodo - * @param string $sqlANDOR "AND", "OR" or "" - * @return void + * @param string $sqlANDOR "AND", "OR" or "" sql condition + * @return string sql request */ function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDOR = "AND") { @@ -1877,6 +1876,8 @@ function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDO if ($donetodo == 'todo') $sql .= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))"; elseif ($donetodo == 'done') $sql .= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))"; if (is_array($filters) && $filters['search_agenda_label']) $sql .= natural_search('a.label', $filters['search_agenda_label']); + + return $sql; } /** @@ -1884,7 +1885,7 @@ function addEventTypeSQL(&$sql, $actioncode, $donetodo, $now, $filters, $sqlANDO * * @param string $actioncode Action code * @param string $objcon objcon - * @param Object $filterobj + * @param Object $filterobj filterobj * @return string */ function addMailingEventTypeSQL($actioncode, $objcon, $filterobj) From 1f466f38461bf88cb3f9401cf317c6b535a3c8a6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 3 Jul 2020 00:57:15 +0200 Subject: [PATCH 6/6] Update company.lib.php --- htdocs/core/lib/company.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 2d58e545b41..1d5b5c1b3dc 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -1562,10 +1562,10 @@ function show_actions_done($conf, $langs, $db, $filterobj, $objcon = '', $noprin $out .= ''; $out .= ''; $out .= ''; - $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, !empty($conf->global->AGENDA_USE_MULTISELECT_TYPE) ? 1 : -1, 1); + $out .= $formactions->select_type_actions($actioncode, "actioncode", '', empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : -1, 0, (empty($conf->global->AGENDA_USE_MULTISELECT_TYPE) ? 0 : 1), 1); $out .= ''; $out .= ''; - $out .= ''.$form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1).''; + $out .= ''.$form->selectDateToDate($tms_start, $tms_end, 'dateevent', 1).''; $out .= ''; $out .= ''; $out .= '';