function getUgroupMembers($ugroupId, $groupId)
 {
     require_once 'www/project/admin/ugroup_utils.php';
     if ($ugroupId > 100) {
         $sql = ugroup_db_get_members($ugroupId);
     } else {
         $sql = ugroup_db_get_dynamic_members($ugroupId, false, $groupId);
     }
     return $this->retrieve($sql);
 }
Exemplo n.º 2
0
            header('Content-Disposition: filename=' . $name);
            header('Content-Type: text/csv');
            echo build_csv_header($col_list, $lbl_list) . $eol;
            $ugs = ugroup_db_get_existing_ugroups($group_id, array($GLOBALS['UGROUP_PROJECT_MEMBERS'], $GLOBALS['UGROUP_PROJECT_ADMIN']));
            while ($ugrp = db_fetch_array($ugs)) {
                if ($ugrp['ugroup_id'] <= 100) {
                    $sqlUsers = ugroup_db_get_dynamic_members($ugrp['ugroup_id'], false, $group_id);
                } else {
                    $sqlUsers = ugroup_db_get_members($ugrp['ugroup_id']);
                }
                $users = db_query($sqlUsers);
                while ($user = db_fetch_array($users)) {
                    $r = array('group' => util_translate_name_ugroup($ugrp['name']), 'username' => $user['user_name'], 'realname' => $um->getUserById($user['user_id'])->getRealname());
                    echo build_csv_record($col_list, $r) . $eol;
                }
            }
            break;
        case 'user_groups_format':
            echo '<h3>' . $Language->getText('project_export_user_groups', 'exp_format') . '</h3>';
            echo '<p>' . $Language->getText('project_export_user_groups', 'exp_format_msg') . '</p>';
            // Pick-up a random project member
            $sqlUsers = ugroup_db_get_dynamic_members($GLOBALS['UGROUP_PROJECT_MEMBERS'], false, $group_id);
            $users = db_query($sqlUsers);
            $uRow = db_fetch_array($users);
            $user = $um->getUserById($uRow['user_id']);
            $dsc_list = array('group' => $GLOBALS['Language']->getText('project_export_user_groups', 'user_group_desc'), 'username' => $GLOBALS['Language']->getText('project_export_user_groups', 'user_username_desc', array($GLOBALS['sys_name'])), 'realname' => $GLOBALS['Language']->getText('project_export_user_groups', 'user_realname_desc'));
            $record = array('group' => util_translate_name_ugroup('project_members'), 'username' => $user->getName(), 'realname' => $user->getRealName());
            display_exported_fields($col_list, $lbl_list, $dsc_list, $record);
            break;
    }
}
Exemplo n.º 3
0
 /**
  * Get uGroup members for both dynamic & sttic uGroups
  *
  * @param Integer $ugroupId Id of the uGroup
  * @param Integer $groupId  Id of the project
  * @param Integer $limit
  * @param Integer $offset
  *
  * @return DataAccessResult | false
  */
 public function searchUsersByDynamicUGroupIdPaginated($ugroupId, $groupId, $limit, $offset)
 {
     $ugroupId = $this->da->escapeInt($ugroupId);
     $groupId = $this->da->escapeInt($groupId);
     $limit = $this->da->escapeInt($limit);
     $offset = $this->da->escapeInt($offset);
     $sql = ugroup_db_get_dynamic_members($ugroupId, false, $groupId);
     if (!$sql) {
         return false;
     }
     $sql .= " LIMIT {$offset}, {$limit}";
     // Nicolas Terray approved :)
     return $this->retrieve($sql);
 }
Exemplo n.º 4
0
/**
 * Filter dynamic ugroups that contain project admins.
 * Retun is the number of non project admins
 * in the filtered ugroups.
 *
 * @param Integer $groupId
 * @param Array   $ugroups
 * @param Array   $validUgroups
 *
 * @return Integer
 */
function ugroup_count_non_admin_for_dynamic_ugroups($groupId, $ugroups, &$validUGroups)
{
    $containNonAdmin = 0;
    foreach ($ugroups as $ugroupId) {
        $sql = ugroup_db_get_dynamic_members($ugroupId, null, $groupId);
        $arrayUsers = ugroup_count_project_admins($groupId, $sql);
        if ($arrayUsers['admins'] > 0) {
            $validUGroups[] = $ugroupId;
            $containNonAdmin += $arrayUsers['non_admins'];
        }
    }
    return $containNonAdmin;
}
 /**
  * Get the list of people to notify when Watermarking is disabled 
  * 
  * Notify the Docman admins.
  * Current code is not really clean, but as there is no clean interface
  * for ugroups & permission manangement...
  * 
  * @return Array
  */
 public function getPeopleToNotifyWhenWatermarkingIsDisabled($item)
 {
     $res = permission_db_authorized_ugroups('PLUGIN_DOCMAN_ADMIN', $item->getGroupId());
     if (db_numrows($res) == 0) {
         $res = permission_db_get_defaults('PLUGIN_DOCMAN_ADMIN');
     }
     $admins = array();
     $um = UserManager::instance();
     while ($row = db_fetch_array($res)) {
         if ($row['ugroup_id'] < 101) {
             $sql = ugroup_db_get_dynamic_members($row['ugroup_id'], 0, $item->getGroupId());
         } else {
             $sql = ugroup_db_get_members($row['ugroup_id']);
         }
         $res_members = db_query($sql);
         while ($row_members = db_fetch_array($res_members)) {
             $admins[] = $um->getUserById($row_members['user_id'])->getEmail();
         }
     }
     return $admins;
 }
 /**
  * Get the list of users to be notified by the event
  *
  * @return array
  */
 function getNotifiedPeople()
 {
     global $art_field_fact;
     //Instantiate a new Artifact object
     $group = ProjectManager::instance()->getProject($this->getGroupId());
     $at = new ArtifactType($group, $this->getGroupArtifactId());
     $art_field_fact = new ArtifactFieldFactory($at);
     $art = new Artifact($at, $this->getArtifactId(), false);
     $notified_people = array();
     $sql = sprintf('SELECT notified_people FROM artifact_date_reminder_settings' . ' WHERE reminder_id=%d' . ' AND group_artifact_id=%d' . ' AND field_id=%d', db_ei($this->getReminderId()), db_ei($this->getGroupArtifactId()), db_ei($this->getFieldId()));
     $res = db_query($sql);
     $notif = db_result($res, 0, 'notified_people');
     $notif_array = explode(",", $notif);
     foreach ($notif_array as $item) {
         if ($item == 1) {
             //Submitter
             $submitter = $art->getSubmittedBy();
             //add submitter in the 'notified_people' array
             if (!in_array(user_getemail($submitter), $notified_people) && $submitter != 100 && $this->isUserAllowedToBeNotified($submitter)) {
                 $count = count($notified_people);
                 $notified_people[$count] = user_getemail($submitter);
             }
         } else {
             if ($item == 2) {
                 //Assigned To
                 $assignee_array = array();
                 $multi_assigned_to = $art_field_fact->getFieldFromName('multi_assigned_to');
                 if (is_object($multi_assigned_to)) {
                     //Multi-Assigned To field
                     if ($multi_assigned_to->isUsed()) {
                         $assignee_array = $art->getMultiAssignedTo();
                     }
                 } else {
                     $assigned_to = $art_field_fact->getFieldFromName('assigned_to');
                     if (is_object($assigned_to)) {
                         //Assigned To field
                         if ($assigned_to->isUsed()) {
                             $assignee_array = array($art->getValue('assigned_to'));
                         }
                     }
                 }
                 $index = count($notified_people);
                 if (count($assignee_array) > 0) {
                     foreach ($assignee_array as $assignee) {
                         if (!in_array(user_getemail($assignee), $notified_people) && $assignee != 100 && $this->isUserAllowedToBeNotified($assignee)) {
                             $notified_people[$index] = user_getemail($assignee);
                             $index++;
                         }
                     }
                 }
             } else {
                 if ($item == 3) {
                     //CC
                     $cc_array = $art->getCCIdList();
                     if (count($cc_array) > 0) {
                         $index = count($notified_people);
                         foreach ($cc_array as $cc_id) {
                             $cc = user_getemail($cc_id);
                             if (!in_array($cc, $notified_people) && $this->isUserAllowedToBeNotified($cc_id)) {
                                 //add CC list in the 'notified_people' array
                                 $notified_people[$index] = $cc;
                                 $index++;
                             }
                         }
                     }
                 } else {
                     if ($item == 4) {
                         //Commenter
                         $res_com = $art->getCommenters();
                         if (db_numrows($res_com) > 0) {
                             $index = count($notified_people);
                             while ($row = db_fetch_array($res_com)) {
                                 $commenter = $row['mod_by'];
                                 if (!in_array(user_getemail($commenter), $notified_people) && $commenter != 100 && $this->isUserAllowedToBeNotified($commenter)) {
                                     //add Commenters in the 'notified_people' array
                                     $notified_people[$index] = user_getemail($commenter);
                                     $index++;
                                 }
                             }
                         }
                     } else {
                         if (preg_match("/^g/", $item)) {
                             // user-group
                             $ugr_id = (int) substr($item, 1);
                             if ($ugr_id > 100) {
                                 // user-defined ugroup
                                 $qry = ugroup_db_get_members($ugr_id);
                                 $result = db_query($qry);
                                 if (db_numrows($result) > 0) {
                                     $idx = count($notified_people);
                                     while ($row = db_fetch_array($result)) {
                                         $usr = $row['user_id'];
                                         if (!in_array(user_getemail($usr), $notified_people) && $usr != 100 && $this->isUserAllowedToBeNotified($usr)) {
                                             //add ugroup members in the 'notified_people' array
                                             $notified_people[$idx] = user_getemail($usr);
                                             $idx++;
                                         }
                                     }
                                 }
                             } else {
                                 // predefined ugroup
                                 $qry = ugroup_db_get_dynamic_members($ugr_id, $this->getGroupArtifactId(), $this->getGroupId());
                                 $result = db_query($qry);
                                 if (db_numrows($result) > 0) {
                                     $idx = count($notified_people);
                                     while ($row = db_fetch_array($result)) {
                                         $usr = $row['user_id'];
                                         if (!in_array(user_getemail($usr), $notified_people) && $usr != 100 && $this->isUserAllowedToBeNotified($usr)) {
                                             //add ugroup members in the 'notified_people' array
                                             $notified_people[$idx] = user_getemail($usr);
                                             $idx++;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $notified_people;
 }
 /**
  * Get all values to be displayed in the field depending of a ugroup list
  *
  * @param array  $ugroups, a list of ugroups
  * @param string $keyword
  *
  * @return Tracker_FormElement_Field_List_Bind_UsersValue[]
  */
 protected function getAllValuesByUGroupList($ugroups, $keyword = null)
 {
     if ($this->values) {
         return $this->values;
     }
     $this->values = array();
     $da = $this->getDefaultValueDao()->getDa();
     $sql = array();
     $tracker = $this->field->getTracker();
     $tracker_id = $da->escapeInt($tracker->id);
     $user_helper = UserHelper::instance();
     foreach ($ugroups as $ugroup) {
         if ($ugroup) {
             switch ($ugroup) {
                 case 'group_members':
                     $sql[] = ugroup_db_get_dynamic_members($GLOBALS['UGROUP_PROJECT_MEMBERS'], $tracker_id, $tracker->group_id, true, $keyword);
                     break;
                 case 'group_admins':
                     $sql[] = ugroup_db_get_dynamic_members($GLOBALS['UGROUP_PROJECT_ADMIN'], $tracker_id, $tracker->group_id, true, $keyword);
                     break;
                 case 'artifact_submitters':
                     $display_name_sql = $user_helper->getDisplayNameSQLQuery();
                     $order_by_sql = $user_helper->getDisplayNameSQLOrder();
                     if ($keyword) {
                         $keyword = $da->quoteSmart('%' . $keyword . '%');
                     }
                     $keyword_sql = $keyword ? "HAVING full_name LIKE {$keyword}" : "";
                     $sql[] = "(\n                            SELECT DISTINCT user.user_id, {$display_name_sql}, user.user_name\n                                FROM tracker_artifact AS a\n                                INNER JOIN user\n                                    ON ( user.user_id = a.submitted_by AND a.tracker_id = {$tracker_id} )\n                                {$keyword_sql}\n                                ORDER BY {$order_by_sql}\n                        )";
                     break;
                 case 'artifact_modifiers':
                     $display_name_sql = $user_helper->getDisplayNameSQLQuery();
                     $order_by_sql = $user_helper->getDisplayNameSQLOrder();
                     if ($keyword) {
                         $keyword = $da->quoteSmart('%' . $keyword . '%');
                     }
                     $keyword_sql = $keyword ? "HAVING full_name LIKE {$keyword}" : "";
                     $sql[] = "(\n                            SELECT DISTINCT user.user_id, {$display_name_sql}, user.user_name\n                                FROM tracker_artifact AS a\n                                INNER JOIN tracker_changeset c ON a.id = c.artifact_id\n                                INNER JOIN user\n                                    ON ( user.user_id = c.submitted_by AND a.tracker_id = {$tracker_id} )\n                                {$keyword_sql}\n                                ORDER BY {$order_by_sql}\n                        )";
                     break;
                 default:
                     if (preg_match('/ugroup_([0-9]+)/', $ugroup, $matches)) {
                         if (strlen($matches[1]) > 2) {
                             $sql[] = ugroup_db_get_members($matches[1], true, $keyword);
                         } else {
                             $sql[] = ugroup_db_get_dynamic_members($matches[1], $tracker_id, $tracker->group_id, true, $keyword);
                         }
                     }
             }
         }
     }
     if (!empty($sql) && $sql[0] != null) {
         $dao = $this->getDefaultValueDao();
         foreach ($dao->retrieve(implode(' UNION ', $sql)) as $row) {
             $this->values[$row['user_id']] = new Tracker_FormElement_Field_List_Bind_UsersValue($row['user_id'], $row['user_name'], $row['full_name']);
         }
     }
     return $this->values;
 }
Exemplo n.º 8
0
 /**
  * Return all possible values for a select box field
  * Rk: if the checked value is given then it means that we want this value
  *     in the list in any case (even if it is hidden and active_only is requested)
  *
  * @return array
  */
 function getFieldPredefinedValues($group_artifact_id, $checked = false, $by_field_id = false, $active_only = true, $use_cache = false, $with_display_preferences = false)
 {
     // ArtifactTypeHtml object created in index.php
     global $ath, $RES_CACHE;
     // The "Assigned_to" box requires some special processing
     // because possible values  are project members) and they are
     // not stored in the artifact_field_value table but in the user_group table
     $value_func = $this->getGlobalValueFunction();
     if (count($value_func) > 0) {
         $show_suspended = true;
         for ($i = 0; $i < count($value_func); $i++) {
             if ($value_func[$i] == 'group_members') {
                 $qry_value[$i] = ugroup_db_get_dynamic_members($GLOBALS['UGROUP_PROJECT_MEMBERS'], $group_artifact_id, $ath->getGroupID(), $with_display_preferences, null, $show_suspended);
             } else {
                 if ($value_func[$i] == 'group_admins') {
                     $qry_value[$i] = ugroup_db_get_dynamic_members($GLOBALS['UGROUP_PROJECT_ADMIN'], $group_artifact_id, $ath->getGroupID(), $with_display_preferences, null, $show_suspended);
                 } else {
                     if ($value_func[$i] == 'tracker_admins') {
                         $qry_value[$i] = ugroup_db_get_dynamic_members($GLOBALS['UGROUP_TRACKER_ADMIN'], $group_artifact_id, $ath->getGroupID(), $with_display_preferences, null, $show_suspended);
                     } else {
                         if ($value_func[$i] == 'artifact_submitters') {
                             $qry_value[$i] = $ath->getSubmitters($with_display_preferences);
                         } else {
                             if (preg_match('/ugroup_([0-9]+)/', $value_func[$i], $matches)) {
                                 if (strlen($matches[1]) > 2) {
                                     $qry_value[$i] = ugroup_db_get_members($matches[1], $with_display_preferences);
                                 } else {
                                     $qry_value[$i] = ugroup_db_get_dynamic_members($matches[1], $group_artifact_id, $ath->getGroupID(), $with_display_preferences, null, $show_suspended);
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $qry = $qry_value[0];
         if (count($qry_value) > 1) {
             for ($i = 1; $i < count($qry_value); $i++) {
                 $qry = $qry . " UNION " . $qry_value[$i];
             }
         }
         $res_value = db_query($qry);
     } else {
         // If only active field
         $status_cond = "";
         if ($active_only) {
             if ($checked && !is_array($checked)) {
                 //TODO: investigate why $checked may be an array
                 $status_cond = "AND  (status IN ('A','P') OR value_id='" . db_ei($checked) . "') ";
             } else {
                 $status_cond = "AND  status IN ('A','P') ";
             }
         }
         // CAUTION !! the fields value_id and value must be first in the
         // select statement because the output is used in the html_build_select_box
         // function
         // Look for project specific values first
         $sql = "SELECT value_id,value,field_id,group_artifact_id,description,order_id,status " . "FROM artifact_field_value_list " . "WHERE group_artifact_id=" . db_ei($group_artifact_id) . " AND field_id= " . db_ei($this->field_id) . " " . $status_cond . " ORDER BY order_id ASC";
         // Use cache ?
         if ($use_cache) {
             if (isset($RES_CACHE[$sql])) {
                 $res_value = $RES_CACHE[$sql];
             } else {
                 $res_value = db_query($sql);
                 $RES_CACHE[$sql] = $res_value;
             }
         } else {
             $res_value = db_query($sql);
         }
         $rows = db_numrows($res_value);
     }
     return $res_value;
 }
 /**
  * @param string $keyword
  *
  * @return array
  */
 public function getAllValues($keyword = null)
 {
     $sql = array();
     $da = CodendiDataAccess::instance();
     if (!$this->values) {
         $this->values = array();
         if (count($this->value_function) > 0) {
             $sql = array();
             $uh = UserHelper::instance();
             $tracker = $this->field->getTracker();
             foreach ($this->value_function as $function) {
                 if ($function) {
                     switch ($function) {
                         case 'group_members':
                             $sql[] = ugroup_db_get_dynamic_members($GLOBALS['UGROUP_PROJECT_MEMBERS'], $tracker->id, $tracker->group_id, true, $keyword);
                             break;
                         case 'group_admins':
                             $sql[] = ugroup_db_get_dynamic_members($GLOBALS['UGROUP_PROJECT_ADMIN'], $tracker->id, $tracker->group_id, true, $keyword);
                             break;
                         case 'artifact_submitters':
                             $da = CodendiDataAccess::instance();
                             $field_id = $da->escapeInt($this->field->id);
                             $tracker_id = $da->escapeInt($tracker->id);
                             if ($keyword) {
                                 $keyword = $da->quoteSmart('%' . $keyword . '%');
                             }
                             $sql[] = "(SELECT DISTINCT user.user_id, user.user_name, " . $uh->getDisplayNameSQLQuery() . "\n                                          FROM tracker_artifact AS a\n                                               INNER JOIN user\n                                               ON ( user.user_id = a.submitted_by AND a.tracker_id = {$tracker->id} )\n                                          " . ($keyword ? "HAVING full_name LIKE {$keyword}" : "") . "\n                                          ORDER BY " . $uh->getDisplayNameSQLOrder() . "\n                                          )";
                             break;
                         default:
                             if (preg_match('/ugroup_([0-9]+)/', $function, $matches)) {
                                 if (strlen($matches[1]) > 2) {
                                     $sql[] = ugroup_db_get_members($matches[1], true, $keyword);
                                 } else {
                                     $sql[] = ugroup_db_get_dynamic_members($matches[1], $tracker->id, $tracker->group_id, true, $keyword);
                                 }
                             }
                             break;
                     }
                 }
             }
             if ($sql) {
                 $dao = new DataAccessObject();
                 $this->values = array();
                 foreach ($dao->retrieve(implode(' UNION ', $sql)) as $row) {
                     $this->values[$row['user_id']] = new Tracker_FormElement_Field_List_Bind_UsersValue($row['user_id'], $row['user_name'], $row['full_name']);
                 }
             }
         }
     }
     return $this->values;
 }
Exemplo n.º 10
0
 /**
  * Get uGroup members for both dynamic & sttic uGroups
  *
  * @param Integer $ugroupId Id of the uGroup
  * @param Integer $groupId  Id of the project
  *
  * @return DataAccessResult
  */
 public function searchUserByDynamicUGroupId($ugroupId, $groupId)
 {
     $sql = ugroup_db_get_dynamic_members($ugroupId, false, $groupId);
     return $this->retrieve($sql);
 }