public function add2group($groupID) {
if (is_numeric($groupID) && isset($this->_aliases['civicrm_contact'])) {
$select = "SELECT DISTINCT {$this->_aliases['civicrm_contact']}.id AS addtogroup_contact_id, ";
- $select = str_ireplace('SELECT SQL_CALC_FOUND_ROWS ', $select, $this->_select);
+
+ // here are we are prepending / adding contact id field that could be used for adding group
+ // so first check for "SELECT SQL_CALC_FOUND_ROWS" and if does not exist replace "SELECT"
+ if (preg_match('/^SELECT SQL_CALC_FOUND_ROWS/', $this->_select)) {
+ $select = str_ireplace('SELECT SQL_CALC_FOUND_ROWS ', $select, $this->_select);
+ }
+ else {
+ $select = str_ireplace('SELECT ', $select, $this->_select);
+ }
$sql = "{$select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_having} {$this->_orderBy}";
$sql = str_replace('WITH ROLLUP', '', $sql);
// now build the query for duration sum
$this->from(TRUE);
- $this->customDataFrom();
$this->where(TRUE);
// build the query to calulate duration sum
// assign variables to templates
$this->doTemplateAssignment($rows);
+ //reset the sql building to default, which is used / called during other actions like "add to group"
+ // now build the query for duration sum
+ $this->from();
+ $this->where();
+
// do print / pdf / instance stuff if needed
$this->endPostProcess($rows);
}