<commit_before><?php
/**
 * groups_Ajax.php
 *
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.23
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email <EMAIL>.
 *
 */
if (($RBAC_Response=$RBAC->userCanAccess("PM_USERS"))!=1) return $RBAC_Response;
G::LoadInclude('ajax');
$_POST['action'] = get_ajax_value('action');

switch ($_POST['action'])
{
  case 'showUsers':
    G::LoadClass('groups');
    $oGroups = new Groups();
    $oGroup  = new Groupwf();
    $aFields = $oGroup->load($_POST['sGroupUID']);
    global $G_PUBLISH;
    $G_PUBLISH = new Publisher();
    //$G_PUBLISH->AddContent('xmlform', 'xmlform', 'groups/groups_UsersListTitle', '', array('GRP_NAME' => $aFields['GRP_TITLE']));
    $G_PUBLISH->AddContent('propeltable', 'groups/paged-table2', 'groups/groups_UsersList', $oGroups->getUsersGroupCriteria($_POST['sGroupUID']), array('GRP_UID' => $_POST['sGroupUID'], 'GRP_NAME' => $aFields['GRP_TITLE']));
    
    $oHeadPublisher =& headPublisher::getSingleton();
    $oHeadPublisher->addScriptCode("groupname=\"{$aFields["GRP_TITLE"]}\";");
    
    G::RenderPage('publish', 'raw');
  break;

  case 'assignUser':
    G::LoadClass('groups');
    $oGroup = new Groups();
    $oGroup->addUserToGroup($_POST['GRP_UID'], $_POST['USR_UID']);
  break;

  case 'assignAllUsers':
    G::LoadClass('groups');
    $oGroup = new Groups();
    $aUsers=explode(',', $_POST['aUsers']);
    
    for($i=0; $i<count($aUsers); $i++)
    {
      $oGroup->addUserToGroup($_POST['GRP_UID'], $aUsers[$i]);
    }
  break;

  case 'ofToAssignUser':
    G::LoadClass('groups');
    $oGroup = new Groups();
    $oGroup->removeUserOfGroup($_POST['GRP_UID'], $_POST['USR_UID']);
  break;

  case 'verifyGroupname':
    $_POST['sOriginalGroupname'] = get_ajax_value('sOriginalGroupname');
    $_POST['sGroupname']         = get_ajax_value('sGroupname');
    if ($_POST['sOriginalGroupname'] == $_POST['sGroupname'])
    {
      echo '0';
    }
    else
    {
      require_once 'classes/model/Groupwf.php';
      G::LoadClass('Groupswf');
      $oGroup = new Groupwf();
      $oCriteria=$oGroup->loadByGroupname($_POST['sGroupname']);
      $oDataset = GroupwfPeer::doSelectRS($oCriteria);
      $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
      $oDataset->next();
      $aRow = $oDataset->getRow();
      if (!$aRow)
      {
        echo '0';
      }
      else
      {
        echo '1';
      }
    }
    break;
  case 'groupsList':
    require_once 'classes/model/Groupwf.php';
    require_once 'classes/model/TaskUser.php';
    require_once 'classes/model/GroupUser.php';
    G::LoadClass('configuration');
    
    $co = new Configurations();
    $config = $co->getConfiguration('groupList', 'pageSize','',$_SESSION['USER_LOGGED']);
    $env = $co->getConfiguration('ENVIRONMENT_SETTINGS', '');
    $limit_size = isset($config['pageSize']) ? $config['pageSize'] : 20;
    $start   = isset($_REQUEST['start'])  ? $_REQUEST['start'] : 0;
    $limit   = isset($_REQUEST['limit'])  ? $_REQUEST['limit'] : $limit_size; 
    $filter = isset($_REQUEST['textFilter']) ? $_REQUEST['textFilter'] : '';
    
    $oCriteria = new Criteria('workflow');
    $oCriteria->addSelectColumn(GroupwfPeer::GRP_UID);
    $oCriteria->addJoin(GroupwfPeer::GRP_UID, ContentPeer::CON_ID, Criteria::LEFT_JOIN);
    $oCriteria->add(ContentPeer::CON_CATEGORY,'GRP_TITLE');
    $oCriteria->add(ContentPeer::CON_LANG,SYS_LANG);
    if ($filter != ''){
      $oCriteria->add(ContentPeer::CON_VALUE, '%'.$filter.'%', Criteria::LIKE);
    }
    $totalRows = GroupwfPeer::doCount($oCriteria);
    
    $oCriteria = new Criteria('workflow');   
    $oCriteria->clearSelectColumns();
    $oCriteria->addSelectColumn(GroupwfPeer::GRP_UID);
    $oCriteria->addSelectColumn(GroupwfPeer::GRP_STATUS);
    $oCriteria->addSelectColumn(ContentPeer::CON_VALUE);
    $oCriteria->addAsColumn('GRP_TASKS', 0);
    $oCriteria->addAsColumn('GRP_USERS', 0);
    $oCriteria->addJoin(GroupwfPeer::GRP_UID, ContentPeer::CON_ID, Criteria::LEFT_JOIN);
    $oCriteria->add(ContentPeer::CON_CATEGORY,'GRP_TITLE');
    $oCriteria->add(ContentPeer::CON_LANG,SYS_LANG); 
    if ($filter != ''){
      $oCriteria->add(ContentPeer::CON_VALUE, '%'.$filter.'%', Criteria::LIKE);
    }
    $oCriteria->setOffset($start);
    $oCriteria->setLimit($limit);
    
    $oDataset = GroupwfPeer::doSelectRS($oCriteria);
    $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
    
    $tasks = new TaskUser();
    $aTask = $tasks->getCountAllTaksByGroups();
    
    $members = new GroupUser();
    $aMembers = $members->getCountAllUsersByGroup();
    
    $arrData = Array();
    while ($oDataset->next()){
      $arrData[] = $oDataset->getRow();
      $index = sizeof($arrData)-1;
      $arrData[$index]['GRP_TASKS'] = isset($aTask[$arrData[$index]['GRP_UID']]) ? $aTask[$arrData[$index]['GRP_UID']] : 0;
      $arrData[$index]['GRP_USERS'] = isset($aMembers[$arrData[$index]['GRP_UID']]) ? $aMembers[$arrData[$index]['GRP_UID']] : 0;
    }
    echo '{success: true, groups: '.G::json_encode($arrData).', total_groups: '.$totalRows.'}';
    break;
  case 'exitsGroupName':
    require_once 'classes/model/Groupwf.php';
    G::LoadClass('Groupswf');
    $oGroup = new Groupwf();
    $oCriteria=$oGroup->loadByGroupname($_POST['GRP_NAME']);
    $oDataset = GroupwfPeer::doSelectRS($oCriteria);
    $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
    $oDataset->next();
    $aRow = $oDataset->getRow();
    $response = ($aRow) ? 'true' : 'false';
    echo $response;
    break; 
  case 'saveNewGroup':
    G::LoadClass('groups');
    $newGroup['GRP_UID'] = '';
    $newGroup['GRP_STATUS'] = G::toUpper($_POST['status']);
    $newGroup['GRP_TITLE'] = trim($_POST['name']);
    unset($newGroup['GRP_UID']);
    $group = new Groupwf();
    $group->create($newGroup);
    echo '{success: true}';
    break;
  case 'saveEditGroup':
    G::LoadClass('groups');
    $editGroup['GRP_UID'] = $_POST['grp_uid'];
    $editGroup['GRP_STATUS'] = G::toUpper($_POST['status']);
    $editGroup['GRP_TITLE'] = trim($_POST['name']);
    $group = new Groupwf();
    $group->update($editGroup);
    echo '{success: true}';<commit_msg>BUG 7955 this issue was fixed.<commit_after><?php
/**
 * groups_Ajax.php
 *
 * ProcessMaker Open Source Edition
 * Copyright (C) 2004 - 2008 Colosa Inc.23
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
 * Coral Gables, FL, 33134, USA, or email <EMAIL>.
 *
 */
if (($RBAC_Response=$RBAC->userCanAccess("PM_USERS"))!=1) return $RBAC_Response;
G::LoadInclude('ajax');
$_POST['action'] = get_ajax_value('action');

switch ($_POST['action'])
{
  case 'showUsers':
    G::LoadClass('groups');
    $oGroups = new Groups();
    $oGroup  = new Groupwf();
    $aFields = $oGroup->load($_POST['sGroupUID']);
    global $G_PUBLISH;
    $G_PUBLISH = new Publisher();
    //$G_PUBLISH->AddContent('xmlform', 'xmlform', 'groups/groups_UsersListTitle', '', array('GRP_NAME' => $aFields['GRP_TITLE']));
    $G_PUBLISH->AddContent('propeltable', 'groups/paged-table2', 'groups/groups_UsersList', $oGroups->getUsersGroupCriteria($_POST['sGroupUID']), array('GRP_UID' => $_POST['sGroupUID'], 'GRP_NAME' => $aFields['GRP_TITLE']));
    
    $oHeadPublisher =& headPublisher::getSingleton();
    $oHeadPublisher->addScriptCode("groupname=\"{$aFields["GRP_TITLE"]}\";");
    
    G::RenderPage('publish', 'raw');
  break;

  case 'assignUser':
    G::LoadClass('groups');
    $oGroup = new Groups();
    $oGroup->addUserToGroup($_POST['GRP_UID'], $_POST['USR_UID']);
  break;

  case 'assignAllUsers':
    G::LoadClass('groups');
    $oGroup = new Groups();
    $aUsers=explode(',', $_POST['aUsers']);
    
    for($i=0; $i<count($aUsers); $i++)
    {
      $oGroup->addUserToGroup($_POST['GRP_UID'], $aUsers[$i]);
    }
  break;

  case 'ofToAssignUser':
    G::LoadClass('groups');
    $oGroup = new Groups();
    $oGroup->removeUserOfGroup($_POST['GRP_UID'], $_POST['USR_UID']);
  break;

  case 'verifyGroupname':
    $_POST['sOriginalGroupname'] = get_ajax_value('sOriginalGroupname');
    $_POST['sGroupname']         = get_ajax_value('sGroupname');
    if ($_POST['sOriginalGroupname'] == $_POST['sGroupname'])
    {
      echo '0';
    }
    else
    {
      require_once 'classes/model/Groupwf.php';
      G::LoadClass('Groupswf');
      $oGroup = new Groupwf();
      $oCriteria=$oGroup->loadByGroupname($_POST['sGroupname']);
      $oDataset = GroupwfPeer::doSelectRS($oCriteria);
      $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
      $oDataset->next();
      $aRow = $oDataset->getRow();
      if (!$aRow)
      {
        echo '0';
      }
      else
      {
        echo '1';
      }
    }
    break;
  case 'groupsList':
    require_once 'classes/model/Groupwf.php';
    require_once 'classes/model/TaskUser.php';
    require_once 'classes/model/GroupUser.php';
    G::LoadClass('configuration');
    
    $co = new Configurations();
    $config = $co->getConfiguration('groupList', 'pageSize','',$_SESSION['USER_LOGGED']);
    $env = $co->getConfiguration('ENVIRONMENT_SETTINGS', '');
    $limit_size = isset($config['pageSize']) ? $config['pageSize'] : 20;
    $start   = isset($_REQUEST['start'])  ? $_REQUEST['start'] : 0;
    $limit   = isset($_REQUEST['limit'])  ? $_REQUEST['limit'] : $limit_size; 
    $filter = isset($_REQUEST['textFilter']) ? $_REQUEST['textFilter'] : '';
    
    $oCriteria = new Criteria('workflow');
    $oCriteria->addSelectColumn(GroupwfPeer::GRP_UID);
    $oCriteria->addJoin(GroupwfPeer::GRP_UID, ContentPeer::CON_ID, Criteria::LEFT_JOIN);
    $oCriteria->add(ContentPeer::CON_CATEGORY,'GRP_TITLE');
    $oCriteria->add(ContentPeer::CON_LANG,SYS_LANG);
    if ($filter != ''){
      $oCriteria->add(ContentPeer::CON_VALUE, '%'.$filter.'%', Criteria::LIKE);
    }
    $totalRows = GroupwfPeer::doCount($oCriteria);
     
    $oCriteria = new Criteria('workflow');
 
    $oCriteria->addSelectColumn(GroupwfPeer::GRP_UID);
    $oCriteria->addSelectColumn(GroupwfPeer::GRP_STATUS);
    $oDataset = GroupwfPeer::doSelectRS($oCriteria); 
    $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
    global $RBAC; 
 
    $tasks = new TaskUser();
    $aTask = $tasks->getCountAllTaksByGroups();
    
    $members = new GroupUser();
    $aMembers = $members->getCountAllUsersByGroup();
    
    $arrData = Array();
    while ($oDataset->next()){
      $row = $oDataset->getRow();       
      $row['GRP_TASKS'] = isset($aTask[$arrData[$index]['GRP_UID']]) ? $aTask[$arrData[$index]['GRP_UID']] : 0;
      $row['GRP_USERS'] = isset($aMembers[$arrData[$index]['GRP_UID']]) ? $aMembers[$arrData[$index]['GRP_UID']] : 0;      
      $group = GroupwfPeer::retrieveByPK($row['GRP_UID']);  
      $row['CON_VALUE']= $group->getGrpTitle();
      $arrData[] = $row; 
    }

    echo '{success: true, groups: '.G::json_encode($arrData).', total_groups: '.$totalRows.'}'; die;
    break;
  case 'exitsGroupName':
    require_once 'classes/model/Groupwf.php';
    G::LoadClass('Groupswf');
    $oGroup = new Groupwf();
    $oCriteria=$oGroup->loadByGroupname($_POST['GRP_NAME']);
    $oDataset = GroupwfPeer::doSelectRS($oCriteria);
    $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
    $oDataset->next();
    $aRow = $oDataset->getRow();
    $response = ($aRow) ? 'true' : 'false';
    echo $response;
    break; 
  case 'saveNewGroup':
    G::LoadClass('groups');
    $newGroup['GRP_UID'] = '';
    $newGroup['GRP_STATUS'] = G::toUpper($_POST['status']);
    $newGroup['GRP_TITLE'] = trim($_POST['name']);
    unset($newGroup['GRP_UID']);
    $group = new Groupwf();
    $group->create($newGroup);
    echo '{success: true}';
    break;
  case 'saveEditGroup':
    G::LoadClass('groups');
    $editGroup['GRP_UID'] = $_POST['grp_uid'];
    $editGroup['GRP_STATUS'] = G::toUpper($_POST['status']);
    $editGroup['GRP_TITLE'] = trim($_POST['name']);
    $group = new Groupwf();
    $group->update($editGroup);
    echo '{success: true}';
{'fraction_non_alphanumeric': 0.18478016627967941, 'fraction_numerical': 0.005168152198337203, 'mean_word_length': 4.248427672955975, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 90, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2642970', 'n_tokens_mistral': 4612, 'n_tokens_neox': 4431, 'n_words': 801}