5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2009-2010, Roland Mas
7 * Copyright 2010, Franck Villaume - Capgemini
8 * http://fusionforge.org
10 * This file is part of FusionForge.
12 * FusionForge is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published
14 * by the Free Software Foundation; either version 2 of the License,
15 * or (at your option) any later version.
17 * FusionForge is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with FusionForge; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 require_once $gfcommon.'tracker/ArtifactTypes.class.php';
29 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
30 require_once $gfcommon.'forum/Forum.class.php';
31 require_once $gfcommon.'forum/ForumFactory.class.php';
32 require_once $gfcommon.'pm/ProjectGroup.class.php';
33 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
34 require_once $gfcommon.'include/Role.class.php';
35 require_once $gfcommon.'frs/FRSPackage.class.php';
36 require_once $gfcommon.'docman/DocumentGroup.class.php';
37 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
38 require_once $gfcommon.'mail/MailingList.class.php';
39 require_once $gfcommon.'mail/MailingListFactory.class.php';
40 require_once $gfcommon.'survey/SurveyFactory.class.php';
41 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
42 require_once $gfcommon.'include/gettext.php';
43 require_once $gfcommon.'include/GroupJoinRequest.class.php';
45 //the license_id of "Other/proprietary" license
46 define('GROUP_LICENSE_OTHER',126);
48 $LICENSE_NAMES=array();
51 * group_get_licences() - get the licenses list
53 * @return array list of licenses
55 function & group_get_licenses() {
56 global $LICENSE_NAMES;
57 if(empty($LICENSE_NAMES)) {
58 $result = db_query_params ('select * from licenses', array());
59 while($data = db_fetch_array($result)) {
60 $LICENSE_NAMES[$data['license_id']] = $data['license_name'];
63 return $LICENSE_NAMES;
69 * group_get_object() - Get the group object.
71 * group_get_object() is useful so you can pool group objects/save database queries
72 * You should always use this instead of instantiating the object directly.
74 * You can now optionally pass in a db result handle. If you do, it re-uses that query
75 * to instantiate the objects.
77 * IMPORTANT! That db result must contain all fields
78 * from groups table or you will have problems
81 * @param int Result set handle ("SELECT * FROM groups WHERE group_id=xx")
82 * @return object a group object or false on failure
84 function &group_get_object($group_id, $res = false) {
85 //create a common set of group objects
86 //saves a little wear on the database
88 //automatically checks group_type and
89 //returns appropriate object
92 if (!isset($GROUP_OBJ["_".$group_id."_"])) {
94 //the db result handle was passed in
96 $res = db_query_params('SELECT * FROM groups WHERE group_id=$1', array($group_id)) ;
98 if (!$res || db_numrows($res) < 1) {
99 $GROUP_OBJ["_".$group_id."_"]=false;
102 check group type and set up object
104 if (db_result($res,0,'type_id') == 1) {
106 $GROUP_OBJ["_".$group_id."_"] = new Group($group_id, $res);
109 $GROUP_OBJ["_".$group_id."_"] = false;
113 return $GROUP_OBJ["_".$group_id."_"];
116 function &group_get_objects($id_arr) {
119 // Note: if we don't do this, the result may be corrupted
123 foreach ($id_arr as $id) {
125 // See if this ID already has been fetched in the cache
127 if (!isset($GROUP_OBJ["_".$id."_"])) {
131 if (count($fetch) > 0) {
132 $res=db_query_params('SELECT * FROM groups WHERE group_id = ANY ($1)',
133 array(db_int_array_to_any_clause($fetch)));
134 while ($arr = db_fetch_array($res)) {
135 $GROUP_OBJ["_".$arr['group_id']."_"] = new Group($arr['group_id'],$arr);
138 foreach ($id_arr as $id) {
139 $return[] =& $GROUP_OBJ["_".$id."_"];
144 function &group_get_active_projects() {
145 $res = db_query_params('SELECT group_id FROM groups WHERE status=$1',
147 return group_get_objects(util_result_column_to_array($res,0));
150 function &group_get_template_projects() {
151 $res=db_query_params ('SELECT group_id FROM groups WHERE is_template=1 AND status != $1',
153 return group_get_objects (util_result_column_to_array($res,0)) ;
156 function &group_get_object_by_name($groupname) {
157 $res = db_query_params('SELECT * FROM groups WHERE unix_group_name=$1', array($groupname));
158 return group_get_object(db_result($res, 0, 'group_id'), $res);
161 function &group_get_objects_by_name($groupname_arr) {
162 $res = db_query_params('SELECT group_id FROM groups WHERE unix_group_name = ANY ($1)',
163 array(db_string_array_to_any_clause($groupname_arr)));
164 $arr =& util_result_column_to_array($res,0);
165 return group_get_objects($arr);
168 function &group_get_object_by_publicname($groupname) {
169 $res = db_query_params('SELECT * FROM groups WHERE lower(group_name) LIKE $1',
170 array(htmlspecialchars(strtolower($groupname))));
171 return group_get_object(db_result($res, 0, 'group_id'), $res);
174 class Group extends Error {
176 * Associative array of data from db.
178 * @var array $data_array.
183 * array of User objects.
185 * @var array $membersArr.
190 * Whether the use is an admin/super user of this project.
192 * @var bool $is_admin.
197 * Artifact types result handle.
199 * @var int $types_res.
204 * Associative array of data for plugins.
206 * @var array $plugins_data.
212 * Associative array of data for the group menu.
214 * @var array $menu_data.
219 * Group - Group object constructor - use group_get_object() to instantiate.
221 * @param int Required - group_id of the group you want to instantiate.
222 * @param int Database result from select query OR associative array of all columns.
223 * @return boolean success or not
225 function Group($id = false, $res = false) {
228 //setting up an empty object
229 //probably going to call create()
233 if (!$this->fetchData($id)) {
238 // Assoc array was passed in
240 if (is_array($res)) {
241 $this->data_array =& $res;
243 if (db_numrows($res) < 1) {
244 //function in class we extended
245 $this->setError(_('Group Not Found'));
246 $this->data_array=array();
249 //set up an associative array for use by other functions
250 $this->data_array = db_fetch_array_by_row($res, 0);
258 * fetchData - May need to refresh database fields if an update occurred.
260 * @param int The group_id.
261 * @return boolean success or not
263 function fetchData($group_id) {
264 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
266 if (!$res || db_numrows($res) < 1) {
267 $this->setError(sprintf(_('fetchData():: %s'),db_error()));
270 $this->data_array = db_fetch_array($res);
275 * create - Create new group.
277 * This method should be called on empty Group object.
279 * @param object The User object.
280 * @param string The full name of the user.
281 * @param string The Unix name of the user.
282 * @param string The new group description.
283 * @param string The purpose of the group.
284 * @param boolean Whether to send an email or not
285 * @param int The id of the project this new project is based on
286 * @return boolean success or not
288 function create(&$user, $group_name, $unix_name, $description, $purpose, $unix_box='shell1', $scm_box='cvs1', $is_public=1, $send_mail=true, $built_from_template=0) {
289 // $user is ignored - anyone can create pending group
292 if ($this->getID()!=0) {
293 $this->setError(_('Group::create: Group object already exists'));
295 } else if (!$this->validateGroupName($group_name)) {
297 } else if (!account_groupnamevalid($unix_name)) {
298 $this->setError(_('Invalid Unix name'));
300 } else if (!$SYS->sysUseUnixName($unix_name)) {
301 $this->setError(_('Unix name already taken'));
303 } else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
304 array($unix_name))) > 0) {
305 $this->setError(_('Unix name already taken'));
307 } else if (strlen($purpose)<10) {
308 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
310 } else if (strlen($purpose)>1500) {
311 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
313 } else if (strlen($description)<10) {
314 $this->setError(_('Describe in a more comprehensive manner your project.'));
316 } else if (strlen($description)>255) {
317 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
321 srand((double)microtime()*1000000);
322 $random_num = rand(0,1000000);
326 $res = db_query_params('
343 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)',
344 array(htmlspecialchars ($group_name),
347 htmlspecialchars($description),
348 $unix_name.".".forge_get_config('web_host'),
349 $unix_name.".".forge_get_config('web_host'),
353 htmlspecialchars($purpose),
357 $built_from_template));
358 if (!$res || db_affected_rows($res) < 1) {
359 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
364 $id = db_insertid($res, 'groups', 'group_id');
366 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
371 if (!$this->fetchData($id)) {
377 $gjr = new GroupJoinRequest($this);
378 $gjr->create($user->getID(),
379 'Fake GroupJoinRequest to store the creator of a project',
383 // Now, make the user an admin
385 $res=db_query_params('INSERT INTO user_group (user_id, group_id, admin_flags,
386 cvs_flags, artifact_flags, forum_flags, role_id)
387 VALUES ($1, $2, $3, $4, $5, $6, $7)',
388 array($user->getID(),
395 if (!$res || db_affected_rows($res) < 1) {
396 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
402 $hook_params = array();
403 $hook_params['group'] = $this;
404 $hook_params['group_id'] = $this->getID();
405 $hook_params['group_name'] = $group_name;
406 $hook_params['unix_group_name'] = $unix_name;
407 plugin_hook("group_create", $hook_params);
411 $this->sendNewProjectNotificationEmail();
419 * updateAdmin - Update core properties of group object.
421 * This function require site admin privilege.
423 * @param object User requesting operation (for access control).
424 * @param boolean Whether group is publicly accessible (0/1).
425 * @param int Group type (1-project, 2-foundry).
426 * @param string Machine on which group's home directory located.
427 * @param string Domain which serves group's WWW.
431 function updateAdmin(&$user, $is_public, $type_id, $unix_box, $http_domain) {
432 $perm =& $this->getPermission();
434 if (!$perm || !is_object($perm)) {
435 $this->setError(_('Could not get permission.'));
439 if (!$perm->isSuperUser()) {
440 $this->setError(_('Permission denied.'));
446 $res = db_query_params('
448 SET is_public=$1, type_id=$2,
449 unix_box=$3, http_domain=$4
457 if (!$res || db_affected_rows($res) < 1) {
458 $this->setError(_('ERROR: DB: Could not change group properties: %s'),db_error());
463 // Log the audit trail
464 if ($is_public != $this->isPublic()) {
465 $this->addHistory('is_public', $this->isPublic());
467 if ($type_id != $this->data_array['type_id']) {
468 $this->addHistory('type_id', $this->data_array['type_id']);
470 if ($unix_box != $this->data_array['unix_box']) {
471 $this->addHistory('unix_box', $this->data_array['unix_box']);
473 if ($http_domain != $this->data_array['http_domain']) {
474 $this->addHistory('http_domain', $this->data_array['http_domain']);
477 if (!$this->fetchData($this->getID())) {
486 * update - Update number of common properties.
488 * Unlike updateAdmin(), this function accessible to project admin.
490 * @param object User requesting operation (for access control).
491 * @param boolean Whether group is publicly accessible (0/1).
492 * @param string Project's license (string ident).
493 * @param int Group type (1-project, 2-foundry).
494 * @param string Machine on which group's home directory located.
495 * @param string Domain which serves group's WWW.
496 * @return int status.
499 function update(&$user, $group_name, $homepage, $short_description, $use_mail, $use_survey, $use_forum,
500 $use_pm, $use_pm_depend_box, $use_scm, $use_news, $use_docman,
501 $new_doc_address, $send_all_docs, $logo_image_id,
502 $use_ftp, $use_tracker, $use_frs, $use_stats, $tags, $is_public) {
504 $perm =& $this->getPermission();
506 if (!$perm || !is_object($perm)) {
507 $this->setError(_('Could not get permission.'));
511 if (!$perm->isAdmin()) {
512 $this->setError(_('Permission denied.'));
516 // Validate some values
517 if ($this->getPublicName() != $group_name) {
518 if (!$this->validateGroupName($group_name)) {
523 if ($new_doc_address) {
524 $invalid_mails = validate_emails($new_doc_address);
525 if (count($invalid_mails) > 0) {
526 $this->setError(sprintf(ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
531 // in the database, these all default to '1',
532 // so we have to explicity set 0
545 if (!$use_pm_depend_box) {
546 $use_pm_depend_box = 0;
569 if (!$send_all_docs) {
573 $homepage = ltrim($homepage);
575 $homepage = forge_get_config('web_host').'/projects/'.$this->getUnixName().'/';
578 if (strlen(htmlspecialchars($short_description))>255) {
579 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
585 //XXX not yet actived logo_image_id='$logo_image_id',
586 $res = db_query_params('UPDATE groups
589 short_description=$3,
594 use_pm_depend_box=$8,
606 array(htmlspecialchars($group_name),
608 htmlspecialchars($short_description),
627 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
632 if ($this->setTags($tags) === false) {
637 $hook_params = array();
638 $hook_params['group'] = $this;
639 $hook_params['group_id'] = $this->getID();
640 $hook_params['group_homepage'] = $homepage;
641 $hook_params['group_name'] = htmlspecialchars($group_name);
642 $hook_params['group_description'] = htmlspecialchars($short_description);
643 $hook_params['group_ispublic'] = $is_public;
644 if (!plugin_hook("group_update", $hook_params)) {
645 if (!$this->isError()) {
646 $this->setError(_('Error updating project information in plugin_hook group_update'));
652 // Log the audit trail
653 $this->addHistory('Changed Public Info', '');
655 if (!$this->fetchData($this->getID())) {
664 * getID - Simply return the group_id for this object.
666 * @return int group_id.
669 return $this->data_array['group_id'];
673 * getType() - Foundry, project, etc.
675 * @return int The type flag from the database.
678 return $this->data_array['type_id'];
683 * getStatus - the status code.
685 * Statuses char include I,H,A,D.
687 function getStatus() {
688 return $this->data_array['status'];
692 * setStatus - set the status code.
694 * Statuses include I,H,A,D.
696 * @param object User requesting operation (for access control).
697 * @param string Status value.
698 * @return boolean success.
701 function setStatus(&$user, $status) {
704 if (!forge_check_global_perm('approve_projects')) {
705 $this->setPermissionDeniedError();
709 // Projects in 'A' status can only go to 'H' or 'D'
710 // Projects in 'D' status can only go to 'A'
711 // Projects in 'P' status can only go to 'A' OR 'D'
712 // Projects in 'I' status can only go to 'P'
713 // Projects in 'H' status can only go to 'A' OR 'D'
714 $allowed_status_changes = array(
715 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
716 'IP'=>1,'HA'=>1,'HD'=>1
719 // Check that status transition is valid
720 if ($this->getStatus() != $status
721 && !$allowed_status_changes[$this->getStatus().$status]) {
722 $this->setError(_('Invalid Status Change'));
728 $res = db_query_params('UPDATE groups
730 WHERE group_id=$2', array($status, $this->getID()));
732 if (!$res || db_affected_rows($res) < 1) {
733 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
739 // Activate system group, if not yet
740 if (!$SYS->sysCheckGroup($this->getID())) {
741 if (!$SYS->sysCreateGroup($this->getID())) {
742 $this->setError($SYS->getErrorMessage());
747 if (!$this->activateUsers()) {
752 /* Otherwise, the group is not active, and make sure that
753 System group is not active either */
754 } else if ($SYS->sysCheckGroup($this->getID())) {
755 if (!$SYS->sysRemoveGroup($this->getID())) {
756 $this->setError($SYS->getErrorMessage());
762 $hook_params = array();
763 $hook_params['group'] = $this;
764 $hook_params['group_id'] = $this->getID();
765 $hook_params['status'] = $status;
766 plugin_hook("group_setstatus", $hook_params);
770 // Log the audit trail
771 if ($status != $this->getStatus()) {
772 $this->addHistory('Status', $this->getStatus());
775 $this->data_array['status'] = $status;
780 * isProject - Simple boolean test to see if it's a project or not.
782 * @return boolean is_project.
784 function isProject() {
785 if ($this->getType()==1) {
793 * isPublic - Simply returns the is_public flag from the database.
795 * @return boolean is_public.
797 function isPublic() {
798 return $this->data_array['is_public'];
802 * isActive - Database field status of 'A' returns true.
804 * @return boolean is_active.
806 function isActive() {
807 if ($this->getStatus()=='A') {
815 * isTemplate - Simply returns the is_template flag from the database.
817 * @return boolean is_template.
819 function isTemplate() {
820 return $this->data_array['is_template'];
824 * setAsTemplate - Set the template status of a project
826 * @param boolean is_template.
828 function setAsTemplate ($booleanparam) {
830 $booleanparam = $booleanparam ? 1 : 0 ;
831 $res = db_query_params ('UPDATE groups SET is_template=$1 WHERE group_id=$2',
832 array ($booleanparam, $this->getID()));
834 $this->data_array['is_template']=$booleanparam;
844 * getTemplateProject - Return the project template this project is built from
846 * @return object The template project
848 function getTemplateProject() {
849 return group_get_object($this->data_array['built_from_template']);
853 * getUnixName - the unix_name
855 * @return string unix_name.
857 function getUnixName() {
858 return strtolower($this->data_array['unix_group_name']);
862 * getPublicName - the full-length public name.
864 * @return string The group_name.
866 function getPublicName() {
867 return $this->data_array['group_name'];
871 * getRegisterPurpose - the text description of the purpose of this project.
873 * @return string The description.
875 function getRegisterPurpose() {
876 return $this->data_array['register_purpose'];
880 * getDescription - the text description of this project.
882 * @return string The description.
884 function getDescription() {
885 return $this->data_array['short_description'];
889 * getStartDate - the unix time this project was registered.
891 * @return int (unix time) of registration.
893 function getStartDate() {
894 return $this->data_array['register_time'];
898 * getLogoImageID - the id of the logo in the database for this project.
900 * @return int The ID of logo image in db_images table (or 100 if none).
902 function getLogoImageID() {
903 return $this->data_array['logo_image_id'];
907 * getUnixBox - the hostname of the unix box where this project is located.
909 * @return string The name of the unix machine for the group.
911 function getUnixBox() {
912 return $this->data_array['unix_box'];
916 * getSCMBox - the hostname of the scm box where this project is located.
918 * @return string The name of the unix machine for the group.
920 function getSCMBox() {
921 return $this->data_array['scm_box'];
924 * setSCMBox - the hostname of the scm box where this project is located.
926 * @param string The name of the new SCM_BOX
928 function setSCMBox($scm_box) {
930 if ($scm_box == $this->data_array['scm_box']) {
935 $res = db_query_params('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array($scm_box, $this->getID ()));
937 $this->addHistory('scm_box', $this->data_array['scm_box']);
938 $this->data_array['scm_box'] = $scm_box;
943 $this->setError(_("Couldn't insert SCM_BOX to database"));
947 $this->setError(_("SCM Box can't be empty"));
953 * getDomain - the hostname.domain where their web page is located.
955 * @return string The name of the group [web] domain.
957 function getDomain() {
958 return $this->data_array['http_domain'];
962 * getLicense - the license they chose.
964 * @return int ident of group license.
966 function getLicense() {
967 return $this->data_array['license'];
971 * getLicenseName - the name of the license
973 * @return string license name
975 function getLicenseName() {
976 $licenses =& group_get_licenses();
977 if(isset($licenses[$this->data_array['license']])) {
978 return $licenses[$this->data_array['license']];
985 * getLicenseOther - optional string describing license.
987 * @return string The custom license.
989 function getLicenseOther() {
990 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
991 return $this->data_array['license_other'];
998 * getRegistrationPurpose - the text description of the purpose of this project.
1000 * @return string The application for project hosting.
1002 function getRegistrationPurpose() {
1003 return $this->data_array['register_purpose'];
1008 * getAdmins() - Get array of Admin user objects.
1010 * @return array Array of User objects.
1012 function &getAdmins() {
1013 $roles = RBACEngine::getInstance()->getRolesByAllowedAction ('project_admin', $this->getID());
1015 $user_ids = array();
1017 foreach ($roles as $role) {
1018 if (! ($role instanceof RoleExplicit)) {
1021 if ($role->getHomeProject() == NULL
1022 || $role->getHomeProject()->getID() != $this->getID()) {
1026 foreach ($role->getUsers() as $u) {
1027 $user_ids[] = $u->getID();
1030 return user_get_objects(array_unique($user_ids));
1034 Common Group preferences for tools
1038 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
1040 * @return boolean enable_scm.
1042 function enableAnonSCM() {
1044 $r = RoleAnonymous::getInstance();
1045 return $r->hasPermission('scm', $this->getID(), 'read');
1047 if ($this->isPublic() && $this->usesSCM()) {
1048 return $this->data_array['enable_anonscm'];
1055 function SetUsesAnonSCM($booleanparam) {
1057 $booleanparam = $booleanparam ? 1 : 0;
1059 $r = RoleAnonymous::getInstance();
1060 $r->setSetting('scm', $this->getID(), $booleanparam);
1063 $res = db_query_params('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
1064 array($booleanparam, $this->getID()));
1066 $this->data_array['enable_anonscm'] = $booleanparam;
1075 function setUsesSCM($booleanparam) {
1077 $booleanparam = $booleanparam ? 1 : 0;
1078 $res = db_query_params('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
1079 array($booleanparam, $this->getID()));
1081 $this->data_array['use_scm'] = $booleanparam;
1090 * enablePserver - whether or not this group has opted to enable Pserver.
1092 * @return boolean enable_pserver.
1094 function enablePserver() {
1095 if ($this->usesSCM()) {
1096 return $this->data_array['enable_pserver'];
1102 function SetUsesPserver($booleanparam) {
1104 $booleanparam = $booleanparam ? 1 : 0;
1105 $res = db_query_params('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1106 array($booleanparam, $this->getID()));
1108 $this->data_array['enable_pserver'] = $booleanparam;
1117 * usesSCM - whether or not this group has opted to use SCM.
1119 * @return boolean uses_scm.
1121 function usesSCM() {
1122 if (forge_get_config('use_scm')) {
1123 return $this->data_array['use_scm'];
1130 * setUseSCM - Set the SCM usage
1132 * @param boolean enabled/disabled
1134 function setUseSCM ($booleanparam) {
1136 $booleanparam = $booleanparam ? 1 : 0 ;
1137 $res = db_query_params ('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
1138 array ($booleanparam, $this->getID()));
1140 $this->data_array['use_scm']=$booleanparam;
1150 * usesMail - whether or not this group has opted to use mailing lists.
1152 * @return boolean uses_mail.
1154 function usesMail() {
1155 if (forge_get_config('use_mail')) {
1156 return $this->data_array['use_mail'];
1163 * setUseMail - Set the mailing-list usage
1165 * @param boolean enabled/disabled
1167 function setUseMail ($booleanparam) {
1169 $booleanparam = $booleanparam ? 1 : 0 ;
1170 $res = db_query_params ('UPDATE groups SET use_mail=$1 WHERE group_id=$2',
1171 array ($booleanparam, $this->getID()));
1173 $this->data_array['use_mail']=$booleanparam;
1183 * usesNews - whether or not this group has opted to use news.
1185 * @return boolean uses_news.
1187 function usesNews() {
1188 if (forge_get_config('use_news')) {
1189 return $this->data_array['use_news'];
1196 * usesForum - whether or not this group has opted to use discussion forums.
1198 * @return boolean uses_forum.
1200 function usesForum() {
1201 if (forge_get_config('use_forum')) {
1202 return $this->data_array['use_forum'];
1209 * setUseForum - Set the forum usage
1211 * @param boolean enabled/disabled
1213 function setUseForum ($booleanparam) {
1215 $booleanparam = $booleanparam ? 1 : 0 ;
1216 $res = db_query_params ('UPDATE groups SET use_forum=$1 WHERE group_id=$2',
1217 array ($booleanparam, $this->getID()));
1219 $this->data_array['use_forum']=$booleanparam;
1229 * usesStats - whether or not this group has opted to use stats.
1231 * @return boolean uses_stats.
1233 function usesStats() {
1234 return $this->data_array['use_stats'];
1238 * usesFRS - whether or not this group has opted to use file release system.
1240 * @return boolean uses_frs.
1242 function usesFRS() {
1243 if (forge_get_config('use_frs')) {
1244 return $this->data_array['use_frs'];
1251 * setUseFRS - Set the FRS usage
1253 * @param boolean enabled/disabled
1255 function setUseFRS ($booleanparam) {
1257 $booleanparam = $booleanparam ? 1 : 0 ;
1258 $res = db_query_params ('UPDATE groups SET use_frs=$1 WHERE group_id=$2',
1259 array ($booleanparam, $this->getID()));
1261 $this->data_array['use_frs']=$booleanparam;
1271 * usesTracker - whether or not this group has opted to use tracker.
1273 * @return boolean uses_tracker.
1275 function usesTracker() {
1276 if (forge_get_config('use_tracker')) {
1277 return $this->data_array['use_tracker'];
1284 * setUseTracker - Set the tracker usage
1286 * @param boolean enabled/disabled
1288 function setUseTracker ($booleanparam) {
1290 $booleanparam = $booleanparam ? 1 : 0 ;
1291 $res = db_query_params ('UPDATE groups SET use_tracker=$1 WHERE group_id=$2',
1292 array ($booleanparam, $this->getID()));
1294 $this->data_array['use_tracker']=$booleanparam;
1304 * useCreateOnline - whether or not this group has opted to use create online documents option.
1306 * @return boolean use_docman_create_online.
1308 function useCreateOnline() {
1309 if (forge_get_config('use_docman')) {
1310 return $this->data_array['use_docman_create_online'];
1317 * usesDocman - whether or not this group has opted to use docman.
1319 * @return boolean use_docman.
1321 function usesDocman() {
1322 if (forge_get_config('use_docman')) {
1323 return $this->data_array['use_docman'];
1330 * setUseDocman - Set the docman usage
1332 * @param boolean enabled/disabled
1334 function setUseDocman ($booleanparam) {
1336 $booleanparam = $booleanparam ? 1 : 0 ;
1337 $res = db_query_params ('UPDATE groups SET use_docman=$1 WHERE group_id=$2',
1338 array ($booleanparam, $this->getID()));
1340 $this->data_array['use_docman']=$booleanparam;
1350 * useDocmanSearch - whether or not this group has opted to use docman search engine.
1352 * @return boolean use_docman_search.
1354 function useDocmanSearch() {
1355 if (forge_get_config('use_docman')) {
1356 return $this->data_array['use_docman_search'];
1363 * useWebdav - whether or not this group has opted to use webdav interface.
1365 * @return boolean use_docman_search.
1367 function useWebdav() {
1368 if (forge_get_config('use_webdav')) {
1369 return $this->data_array['use_webdav'];
1376 * usesFTP - whether or not this group has opted to use FTP.
1378 * @return boolean uses_ftp.
1380 function usesFTP() {
1381 if (forge_get_config('use_ftp')) {
1382 return $this->data_array['use_ftp'];
1389 * usesSurvey - whether or not this group has opted to use surveys.
1391 * @return boolean uses_survey.
1393 function usesSurvey() {
1394 if (forge_get_config('use_survey')) {
1395 return $this->data_array['use_survey'];
1402 * usesPM - whether or not this group has opted to Project Manager.
1404 * @return boolean uses_projman.
1407 if (forge_get_config('use_pm')) {
1408 return $this->data_array['use_pm'];
1415 * setUsePM - Set the PM usage
1417 * @param boolean enabled/disabled
1419 function setUsePM ($booleanparam) {
1421 $booleanparam = $booleanparam ? 1 : 0 ;
1422 $res = db_query_params ('UPDATE groups SET use_pm=$1 WHERE group_id=$2',
1423 array ($booleanparam, $this->getID()));
1425 $this->data_array['use_pm']=$booleanparam;
1435 * getPlugins - get a list of all available group plugins
1437 * @return array array containing plugin_id => plugin_name
1439 function getPlugins() {
1440 if (!isset($this->plugins_data)) {
1441 $this->plugins_data = array();
1442 $res = db_query_params('SELECT group_plugin.plugin_id, plugins.plugin_name
1443 FROM group_plugin, plugins
1444 WHERE group_plugin.group_id=$1
1445 AND group_plugin.plugin_id=plugins.plugin_id', array($this->getID()));
1446 $rows = db_numrows($res);
1448 for ($i=0; $i<$rows; $i++) {
1449 $plugin_id = db_result($res, $i, 'plugin_id');
1450 $this->plugins_data[$plugin_id] = db_result($res, $i, 'plugin_name');
1453 return $this->plugins_data;
1457 * usesPlugin - returns true if the group uses a particular plugin
1459 * @param string name of the plugin
1460 * @return boolean whether plugin is being used or not
1462 function usesPlugin($pluginname) {
1463 $plugins_data = $this->getPlugins();
1464 foreach ($plugins_data as $p_id => $p_name) {
1465 if ($p_name == $pluginname) {
1473 * added for Codendi compatibility
1474 * usesServices - returns true if the group uses a particular plugin or feature
1476 * @param string name of the plugin
1477 * @return boolean whether plugin is being used or not
1479 function usesService($feature) {
1480 $plugins_data = $this->getPlugins();
1481 $pm = plugin_manager_get_object();
1482 foreach ($plugins_data as $p_id => $p_name) {
1483 if ($p_name == $feature) {
1486 if ($pm->getPluginByName($p_name)->provide($feature)) {
1494 * setPluginUse - enables/disables plugins for the group
1496 * @param string name of the plugin
1497 * @param boolean the new state
1498 * @return string database result
1500 function setPluginUse($pluginname, $val=true) {
1501 if ($val == $this->usesPlugin($pluginname)) {
1502 // State is already good, returning
1505 $res = db_query_params('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1506 array($pluginname));
1507 $rows = db_numrows($res);
1509 // Error: no plugin by that name
1512 $plugin_id = db_result($res,0,'plugin_id');
1514 unset($this->plugins_data);
1516 $res = db_query_params('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1517 array($this->getID(),
1521 $res = db_query_params('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1522 array($this->getID(),
1529 * getDocEmailAddress - get email address(es) to send doc notifications to.
1531 * @return string email address.
1533 function getDocEmailAddress() {
1534 return $this->data_array['new_doc_address'];
1538 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1540 * @return boolean email_on_all_doc_updates.
1542 function docEmailAll() {
1543 return $this->data_array['send_all_docs'];
1548 * getHomePage - The URL for this project's home page.
1550 * @return string homepage URL.
1552 function getHomePage() {
1553 return $this->data_array['homepage'];
1557 * getTags - Tags of this project.
1559 * @return string List of tags. Commat separated
1561 function getTags() {
1562 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1563 $res = db_query_params($sql, array($this->getID()));
1564 return join(', ', util_result_column_to_array($res));
1568 * setTags - Set tags of this project.
1570 * @return string database result.
1572 function setTags($tags) {
1574 $sql = 'DELETE FROM project_tags WHERE group_id=$1';
1575 $res = db_query_params($sql, array($this->getID()));
1577 $this->setError('Deleting old tags: '.db_error());
1581 $inserted = array();
1582 $tags_array = preg_split('/[;,]/', $tags);
1583 foreach ($tags_array as $tag) {
1584 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1585 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1586 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1587 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1592 if ($tag == '' || array_search($tag, $inserted) !== false) continue;
1593 $sql = 'INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1594 $res = db_query_params($sql, array($this->getID(), $tag));
1596 $this->setError(_('Setting tags: ').db_error());
1607 * getPermission - Return a Permission for this Group
1609 * @return object The Permission.
1611 function &getPermission() {
1612 return permission_get_object($this);
1616 function delete($sure, $really_sure, $really_really_sure) {
1617 if (!$sure || !$really_sure || !$really_really_sure) {
1618 $this->setMissingParamsError(_('Please tick all checkboxes.'));
1621 if ($this->getID() == forge_get_config('news_group') ||
1622 $this->getID() == 1 ||
1623 $this->getID() == forge_get_config('stats_group') ||
1624 $this->getID() == forge_get_config('peer_rating_group')) {
1625 $this->setError(_('Cannot Delete System Group'));
1628 $perm =& $this->getPermission();
1629 if (!$perm || !is_object($perm)) {
1630 $this->setPermissionDeniedError();
1632 } elseif ($perm->isError()) {
1633 $this->setPermissionDeniedError();
1635 } elseif (!$perm->isSuperUser()) {
1636 $this->setPermissionDeniedError();
1642 // Remove all the members
1644 $members =& $this->getMembers();
1645 foreach ($members as $i) {
1646 if(!$this->removeUser($i->getID())) {
1647 $this->setError(_('Could not properly remove member:').' '.$i->getID());
1651 // Failsafe until user_group table is gone
1652 $res = db_query_params('DELETE FROM user_group WHERE group_id=$1',
1653 array($this->getID()));
1655 // unlink roles to this project
1656 if ($this->isPublic()) {
1657 $ra = RoleAnonymous::getInstance();
1658 $rl = RoleLoggedIn::getInstance();
1659 $ra->unlinkProject($this);
1660 $rl->unlinkProject($this);
1662 // @todo : unlink all the other roles created in the project...
1667 $atf = new ArtifactTypeFactory($this);
1668 $at_arr =& $atf->getArtifactTypes();
1669 foreach ($at_arr as $i) {
1670 if (!is_object($i)) {
1673 if (!$i->delete(1,1)) {
1674 $this->setError(_('Could not properly delete the tracker:').' '.$i->getErrorMessage());
1681 $ff = new ForumFactory($this);
1682 $f_arr =& $ff->getForums();
1683 foreach ($f_arr as $i) {
1684 if (!is_object($i)) {
1687 if(!$i->delete(1,1)) {
1688 $this->setError(_('Could not properly delete the forum:').' '.$i->getErrorMessage());
1693 // Delete Subprojects
1695 $pgf = new ProjectGroupFactory($this);
1696 $pg_arr =& $pgf->getProjectGroups();
1697 foreach ($pg_arr as $i) {
1698 if (!is_object($i)) {
1701 if (!$i->delete(1,1)) {
1702 $this->setError(_('Could not properly delete the ProjectGroup:').' '.$i->getErrorMessage());
1707 // Delete FRS Packages
1709 $res = db_query_params('SELECT * FROM frs_package WHERE group_id=$1',
1710 array($this->getID()));
1711 while ($arr = db_fetch_array($res)) {
1712 $frsp=new FRSPackage($this, $arr['package_id'], $arr);
1713 if (!$frsp->delete(1, 1)) {
1714 $this->setError(_('Could not properly delete the FRSPackage:').' '.$frsp->getErrorMessage());
1721 $news_group=group_get_object(forge_get_config('news_group'));
1722 $res = db_query_params('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1723 array($this->getID()));
1725 $this->setError(_('Error Deleting News: ').db_error());
1730 for ($i=0; $i<db_numrows($res); $i++) {
1731 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1732 if (!$Forum->delete(1,1)) {
1733 $this->setError(_("Could Not Delete News Forum: %d"),$Forum->getID());
1737 $res = db_query_params('DELETE FROM news_bytes WHERE group_id=$1',
1738 array($this->getID()));
1740 $this->setError(_('Error Deleting News: ').db_error());
1748 $res = db_query_params('DELETE FROM doc_data WHERE group_id=$1',
1749 array($this->getID()));
1751 $this->setError(_('Error Deleting Documents: ').db_error());
1756 $res = db_query_params('DELETE FROM doc_groups WHERE group_id=$1',
1757 array($this->getID()));
1759 $this->setError(_('Error Deleting Documents: ').db_error());
1767 $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
1769 $this->setError(_('Error Deleting Tags: ').db_error());
1775 // Delete group history
1777 $res = db_query_params('DELETE FROM group_history WHERE group_id=$1',
1778 array($this->getID()));
1780 $this->setError(_('Error Deleting Project History: ').db_error());
1786 // Delete group plugins
1788 $res = db_query_params('DELETE FROM group_plugin WHERE group_id=$1',
1789 array($this->getID()));
1791 $this->setError(_('Error Deleting Project Plugins: ').db_error());
1797 // Delete group cvs stats
1799 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1800 array ($this->getID())) ;
1802 $this->setError(_('Error Deleting SCM Statistics: ').db_error());
1810 $sf = new SurveyFactory($this);
1811 $s_arr =& $sf->getSurveys();
1812 foreach ($s_arr as $i) {
1813 if (!is_object($i)) {
1816 if (!$i->delete()) {
1817 $this->setError(_('Could not properly delete the survey'));
1822 // Delete SurveyQuestions
1824 $sqf = new SurveyQuestionFactory($this);
1825 $sq_arr =& $sqf->getSurveyQuestions();
1826 foreach ($sq_arr as $i) {
1827 if (!is_object($i)) {
1830 if (!$i->delete()) {
1831 $this->setError(_('Could not properly delete the survey questions'));
1836 // Delete Mailing List Factory
1838 $mlf = new MailingListFactory($this);
1839 $ml_arr =& $mlf->getMailingLists();
1840 foreach ($ml_arr as $i) {
1841 if (!is_object($i)) {
1844 if (!$i->delete(1,1)) {
1845 $this->setError(_('Could not properly delete the mailing list'));
1852 $res = db_query_params('DELETE FROM trove_group_link WHERE group_id=$1',
1853 array($this->getID()));
1855 $this->setError(_('Error Deleting Trove: ').db_error());
1860 $res = db_query_params('DELETE FROM trove_agg WHERE group_id=$1',
1861 array($this->getID()));
1863 $this->setError(_('Error Deleting Trove: ').db_error());
1871 $res = db_query_params('DELETE FROM project_sums_agg WHERE group_id=$1',
1872 array($this->getID()));
1874 $this->setError(_('Error Deleting Counters: ').db_error());
1879 $res = db_query_params('INSERT INTO deleted_groups (unix_group_name, delete_date, isdeleted) VALUES ($1, $2, $3)',
1880 array($this->getUnixName(),
1884 $this->setError(_('Error Deleting Project:').' '.db_error());
1889 $res = db_query_params('DELETE FROM groups WHERE group_id=$1',
1890 array($this->getID()));
1892 $this->setError(_('Error Deleting Project:').' '.db_error());
1899 $hook_params = array();
1900 $hook_params['group'] = $this;
1901 $hook_params['group_id'] = $this->getID();
1902 plugin_hook("group_delete", $hook_params);
1904 if (forge_get_config('upload_dir') != '' && $this->getUnixName()) {
1905 exec('/bin/rm -rf '.forge_get_config('upload_dir').'/'.$this->getUnixName().'/');
1907 if (forge_get_config('ftp_upload_dir') != '' && $this->getUnixName()) {
1908 exec('/bin/rm -rf '.forge_get_config('ftp_upload_dir').'/'.$this->getUnixName().'/');
1913 $res = db_query_params('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1914 array ($this->getID()));
1915 //echo 'rep_group_act_monthly'.db_error();
1916 $res = db_query_params('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1917 array ($this->getID()));
1918 //echo 'rep_group_act_weekly'.db_error();
1919 $res = db_query_params('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1920 array ($this->getID()));
1921 //echo 'rep_group_act_daily'.db_error();
1922 unset($this->data_array);
1928 Basic functions to add/remove users to/from a group
1929 and update their permissions
1933 * addUser - controls adding a user to a group.
1935 * @param string Unix name of the user to add OR integer user_id.
1936 * @param int The role_id this user should have.
1937 * @return boolean success.
1940 function addUser($user_identifier,$role_id) {
1943 Admins can add users to groups
1946 if (!forge_check_perm ('project_admin', $this->getID())) {
1947 $this->setPermissionDeniedError();
1953 get user id for this user's unix_name
1955 if (is_int ($user_identifier)) { // user_id or user_name
1956 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1958 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1960 if (db_numrows($res_newuser) > 0) {
1962 // make sure user is active
1964 if (db_result($res_newuser,0,'status') != 'A') {
1965 $this->setError(_('User is not active. Only active users can be added.'));
1971 // user was found - set new user_id var
1973 $user_id = db_result($res_newuser,0,'user_id');
1975 $role = new Role($this,$role_id);
1976 if (!$role || !is_object($role)) {
1977 $this->setError(_('Error Getting Role Object'));
1980 } elseif ($role->isError()) {
1981 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1987 $role->addUser(user_get_object ($user_id)) ;
1988 if (!$SYS->sysCheckCreateGroup($this->getID())){
1989 $this->setError($SYS->getErrorMessage());
1993 if (!$SYS->sysCheckCreateUser($user_id)) {
1994 $this->setError($SYS->getErrorMessage());
2001 // if not already a member, add them
2003 $res_member = db_query_params('SELECT user_id
2005 WHERE user_id=$1 AND group_id=$2',
2006 array($user_id, $this->getID()));
2008 if (db_numrows($res_member) < 1) {
2010 // Create this user's row in the user_group table
2012 $res = db_query_params('INSERT INTO user_group
2013 (user_id,group_id,admin_flags,forum_flags,project_flags,
2014 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
2015 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
2027 //verify the insert worked
2028 if (!$res || db_affected_rows($res) < 1) {
2029 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
2034 // check and create if group doesn't exists
2036 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
2037 if (!$SYS->sysCheckCreateGroup($this->getID())){
2038 $this->setError($SYS->getErrorMessage());
2043 // check and create if user doesn't exists
2045 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
2046 if (!$SYS->sysCheckCreateUser($user_id)) {
2047 $this->setError($SYS->getErrorMessage());
2054 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
2055 if (!$role->setUser($user_id)) {
2056 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
2062 // user was already a member
2063 // make sure they are set up
2065 $user= user_get_object($user_id,$res_newuser);
2066 $user->fetchData($user->getID());
2067 $role = new Role($this,$role_id);
2068 if (!$role || !is_object($role)) {
2069 $this->setError(_('Error Getting Role Object'));
2072 } elseif ($role->isError()) {
2073 $this->setError('addUser::roleget::'.$role->getErrorMessage());
2077 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
2078 if (!$role->setUser($user_id)) {
2079 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
2084 // set up their system info
2086 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
2087 if (!$SYS->sysCheckCreateUser($user_id)) {
2088 $this->setError($SYS->getErrorMessage());
2096 // user doesn't exist
2098 $this->setError(_('ERROR: User does not exist'));
2103 $hook_params['group'] = $this;
2104 $hook_params['group_id'] = $this->getID();
2105 $hook_params['user'] = &user_get_object($user_id);
2106 $hook_params['user_id'] = $user_id;
2107 plugin_hook ("group_adduser", $hook_params);
2112 $this->addHistory('Added User',$user_identifier);
2118 * removeUser - controls removing a user from a group.
2120 * Users can remove themselves.
2122 * @param int The ID of the user to remove.
2123 * @return boolean success.
2125 function removeUser($user_id) {
2128 if ($user_id != user_getid()
2129 || !forge_check_perm('project_admin', $this->getID())) {
2130 $this->setPermissionDeniedError();
2137 $user = user_get_object($user_id);
2138 $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user);
2140 foreach ($roles as $role) {
2141 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2142 $found_role = $role;
2146 if ($found_role == NULL) {
2147 $this->setError(sprintf(_('ERROR: User not removed: %s')));
2151 $found_role->removeUser($user);
2152 if (!$SYS->sysGroupCheckUser($this->getID(), $user_id)) {
2153 $this->setError($SYS->getErrorMessage());
2159 $res = db_query_params('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
2160 array($this->getID(),
2162 if (!$res || db_affected_rows($res) < 1) {
2163 $this->setError(_('ERROR: User not removed:').' '.db_error());
2170 // reassign open artifacts to id=100
2172 $res = db_query_params('UPDATE artifact SET assigned_to=100
2173 WHERE group_artifact_id
2174 IN (SELECT group_artifact_id
2175 FROM artifact_group_list
2176 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
2177 array($this->getID(),
2180 $this->setError(_('ERROR: DB: artifact:').' '.db_error());
2186 // reassign open tasks to id=100
2187 // first have to purge any assignments that would cause
2188 // conflict with existing assignment to 100
2190 $res = db_query_params('DELETE FROM project_assigned_to
2191 WHERE project_task_id IN (SELECT pt.project_task_id
2192 FROM project_task pt, project_group_list pgl, project_assigned_to pat
2193 WHERE pt.group_project_id = pgl.group_project_id
2194 AND pat.project_task_id=pt.project_task_id
2195 AND pt.status_id=1 AND pgl.group_id=$1
2196 AND pat.assigned_to_id=$2)
2197 AND assigned_to_id=100',
2198 array($this->getID(),
2201 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'), 1, db_error()));
2205 $res = db_query_params('UPDATE project_assigned_to SET assigned_to_id=100
2206 WHERE project_task_id IN (SELECT pt.project_task_id
2207 FROM project_task pt, project_group_list pgl
2208 WHERE pt.group_project_id = pgl.group_project_id
2209 AND pt.status_id=1 AND pgl.group_id=$1)
2210 AND assigned_to_id=$2',
2211 array($this->getID(),
2214 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'), 2, db_error()));
2220 // Remove user from system
2222 if (!$SYS->sysGroupRemoveUser($this->getID(), $user_id)) {
2223 $this->setError($SYS->getErrorMessage());
2228 $hook_params['group'] = $this;
2229 $hook_params['group_id'] = $this->getID();
2230 $hook_params['user'] = user_get_object($user_id);
2231 $hook_params['user_id'] = $user_id;
2232 plugin_hook ("group_removeuser", $hook_params);
2235 $this->addHistory('Removed User',$user_id);
2242 * updateUser - controls updating a user's role in this group.
2244 * @param int The ID of the user.
2245 * @param int The role_id to set this user to.
2246 * @return boolean success.
2248 function updateUser($user_id,$role_id) {
2251 if (!forge_check_perm ('project_admin', $this->getID())) {
2252 $this->setPermissionDeniedError();
2257 $newrole = RBACEngine::getInstance()->getRoleById ($role_id) ;
2258 if (!$newrole || !is_object($newrole)) {
2259 $this->setError(_('Could Not Get Role'));
2261 } elseif ($newrole->isError()) {
2262 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2264 } elseif ($newrole->getHomeProject() == NULL
2265 || $newrole->getHomeProject()->getID() != $this->getID()) {
2266 $this->setError(_('Wrong destination role'));
2269 $user = user_get_object ($user_id) ;
2270 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
2271 $found_role = NULL ;
2272 foreach ($roles as $role) {
2273 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2274 $found_role = $role ;
2278 if ($found_role == NULL) {
2279 $this->setError(sprintf(_('ERROR: User not removed: %s')));
2283 $found_role->removeUser ($user) ;
2284 $newrole->addUser ($user) ;
2286 $role = new Role($this,$role_id);
2287 if (!$role || !is_object($role)) {
2288 $this->setError(_('Could Not Get Role'));
2290 } elseif ($role->isError()) {
2291 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2294 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
2295 if (!$role->setUser($user_id)) {
2296 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2301 $this->addHistory('Updated User',$user_id);
2306 * addHistory - Makes an audit trail entry for this project.
2308 * @param string The name of the field.
2309 * @param string The Old Value for this $field_name.
2310 * @return database result handle.
2313 function addHistory($field_name, $old_value) {
2314 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
2315 VALUES ($1,$2,$3,$4,$5)',
2316 array ($this->getID(),
2324 * activateUsers - Make sure that group members have unix accounts.
2326 * Setup unix accounts for group members. Can be called even
2327 * if members are already active.
2331 function activateUsers() {
2333 Activate member(s) of the project
2337 $members = $this->getUsers (true) ;
2339 foreach ($members as $member) {
2341 foreach (RBACEngine::getInstance()->getAvailableRolesForUser ($member) as $role) {
2342 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2345 if (!$this->addUser($member->getUnixName(),$role->getID())) {
2352 $res_member = db_query_params('SELECT user_id,role_id FROM user_group WHERE group_id=$1',
2353 array ($this->getID()));
2354 while ($row_member = db_fetch_array($res_member)) {
2355 $u = user_get_object($row_member['user_id']);
2356 if (!$this->addUser($u->getUnixName(),$row_member['role_id'])) {
2366 * getMembers - returns array of User objects for this project
2368 * @return array of User objects for this group.
2370 function getMembers() {
2371 return $this->getUsers (true) ;
2375 * replaceTemplateStrings - fill-in some blanks with project name
2377 * @param string Template string
2378 * @return string String after replacements
2380 function replaceTemplateStrings($string) {
2381 $string = str_replace ('UNIXNAME', $this->getUnixName(), $string) ;
2382 $string = str_replace ('PUBLICNAME', $this->getPublicName(), $string) ;
2383 $string = str_replace ('DESCRIPTION', $this->getDescription(), $string) ;
2388 * approve - Approve pending project.
2390 * @param object The User object who is doing the updating.
2393 function approve(&$user) {
2395 require_once $gfcommon.'widget/WidgetLayoutManager.class.php';
2397 if ($this->getStatus()=='A') {
2398 $this->setError(_("Group already active"));
2404 // Step 1: Activate group and create LDAP entries
2405 if (!$this->setStatus($user, 'A')) {
2410 // Switch to system language for item creation
2411 setup_gettext_from_sys_lang ();
2413 // Create default roles
2415 $idadmin_group = NULL ;
2416 foreach (get_group_join_requests ($this) as $gjr) {
2417 $idadmin_group = $gjr->getUserID() ;
2420 if ($idadmin_group == NULL) {
2421 $idadmin_group = $user->getID();
2424 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2425 array ($this->getID(),
2427 if (db_numrows($admin_group) > 0) {
2428 $idadmin_group = db_result($admin_group,0,'user_id');
2430 $idadmin_group = $user->getID();
2431 db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags) VALUES ($1, $2, $3)',
2432 array ($idadmin_group,
2438 $template = $this->getTemplateProject() ;
2439 $id_mappings = array ();
2440 $seen_local_roles = false ;
2442 // Copy roles from template project
2443 foreach ($template->getRoles() as $oldrole) {
2444 if ($oldrole->getHomeProject() != NULL) {
2445 $role = new Role ($this) ;
2447 // Need to use a different role name so that the permissions aren't set from the hardcoded defaults
2448 $role->create ('TEMPORARY ROLE NAME', $data, true) ;
2449 $role->setName ($oldrole->getName()) ;
2450 $seen_local_roles = true ;
2453 $role->linkProject ($this) ;
2455 $id_mappings['role'][$oldrole->getID()] = $role->getID() ;
2456 // Reuse the project_admin permission
2457 $role->setSetting ('project_admin', $this->getID(), $oldrole->getSetting ('project_admin', $template->getID())) ;
2461 if (!$seen_local_roles) {
2462 $role = new Role($this);
2463 $adminperms = array ('project_admin' => array ($this->getID() => 1)) ;
2464 $role_id = $role->create ('Admin', $adminperms, true) ;
2468 $roles = $this->getRoles() ;
2469 foreach ($roles as $r) {
2470 if ($r->getSetting ('project_admin', $this->getID())) {
2471 $r->addUser (user_get_object ($idadmin_group)) ;
2476 // Temporarily switch to the submitter's identity
2477 $saved_session = session_get_user () ;
2478 session_set_internal ($idadmin_group) ;
2481 if (forge_get_config ('use_tracker')) {
2482 $this->setUseTracker ($template->usesTracker()) ;
2483 if ($template->usesTracker()) {
2484 $oldatf = new ArtifactTypeFactory ($template) ;
2485 foreach ($oldatf->getArtifactTypes() as $o) {
2486 $t = new ArtifactType ($this) ;
2487 $t->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->allowsAnon(),$o->emailAll(),$o->getEmailAddress(),$o->getDuePeriod()/86400,0,$o->getSubmitInstructions(),$o->getBrowseInstructions()) ;
2488 $id_mappings['tracker'][$o->getID()] = $t->getID() ;
2489 $t->cloneFieldsFrom ($o->getID()) ;
2494 if (forge_get_config ('use_pm')) {
2495 $this->setUsePM ($template->usesPM()) ;
2496 if ($template->usesPM()) {
2497 $oldpgf = new ProjectGroupFactory ($template) ;
2498 foreach ($oldpgf->getProjectGroups() as $o) {
2499 $pg = new ProjectGroup ($this) ;
2500 $pg->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo()) ;
2501 $id_mappings['pm'][$o->getID()] = $pg->getID() ;
2506 if (forge_get_config ('use_forum')) {
2507 $this->setUseForum ($template->usesForum()) ;
2508 if ($template->usesForum()) {
2509 $oldff = new ForumFactory ($template) ;
2510 foreach ($oldff->getForums() as $o) {
2511 $f = new Forum ($this) ;
2512 $f->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo(),1,$o->allowAnonymous(),$o->getModerationLevel()) ;
2513 $id_mappings['forum'][$o->getID()] = $f->getID() ;
2518 if (forge_get_config ('use_docman')) {
2519 $this->setUseDocman ($template->usesDocman()) ;
2520 if ($template->usesDocman()) {
2521 $olddgf = new DocumentGroupFactory ($template) ;
2522 // First pass: create all docgroups
2523 $id_mappings['docman_docgroup'][0] = 0 ;
2524 foreach ($olddgf->getDocumentGroups() as $o) {
2525 $ndgf = new DocumentGroup ($this) ;
2526 $ndgf->create($this->replaceTemplateStrings($o->getName())) ;
2527 $id_mappings['docman_docgroup'][$o->getID()] = $ndgf->getID() ;
2529 // Second pass: restore hierarchy links
2530 foreach ($olddgf->getDocumentGroups() as $o) {
2531 $ndgf = new DocumentGroup ($this) ;
2532 $ndgf->fetchData ($id_mappings['docman_docgroup'][$o->getID()]) ;
2533 $ndgf->update ($ndgf->getName(),$id_mappings['docman_docgroup'][$o->getParentID()]) ;
2538 if (forge_get_config ('use_frs')) {
2539 $this->setUseFRS ($template->usesFRS()) ;
2540 if ($template->usesFRS()) {
2541 foreach (get_frs_packages ($template) as $o) {
2542 $newp = new FRSPackage ($this) ;
2543 $nname = $this->replaceTemplateStrings($o->getName()) ;
2544 $newp->create ($nname, $o->isPublic()) ;
2549 if (forge_get_config ('use_mail')) {
2550 $this->setUseMail ($template->usesMail()) ;
2551 if ($template->usesMail()) {
2552 $oldmlf = new MailingListFactory ($template) ;
2553 foreach ($oldmlf->getMailingLists() as $o) {
2554 $ml = new MailingList ($this) ;
2555 $nname = preg_replace ('/^'.$template->getUnixName().'-/','',$o->getName()) ;
2557 $ndescription = $this->replaceTemplateStrings($o->getDescription()) ;
2558 $ml->create ($nname, $ndescription, $o->isPublic()) ;
2563 $this->setUseSCM ($template->usesSCM()) ;
2565 foreach ($template->getPlugins() as $plugin_id => $plugin_name) {
2566 $this->setPluginUse ($plugin_name) ;
2569 foreach ($template->getRoles() as $oldrole) {
2570 $newrole = RBACEngine::getInstance()->getRoleById ($id_mappings['role'][$oldrole->getID()]) ;
2571 if ($oldrole->getHomeProject() != NULL
2572 && $oldrole->getHomeProject()->getID() == $template->getID()) {
2573 $newrole->setPublic ($oldrole->isPublic()) ;
2575 $oldsettings = $oldrole->getSettingsForProject ($template) ;
2577 $sections = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm') ;
2578 foreach ($sections as $section) {
2579 $newrole->setSetting ($section, $this->getID(), $oldsettings[$section][$template->getID()]) ;
2582 $sections = array ('tracker', 'pm', 'forum') ;
2583 foreach ($sections as $section) {
2584 if (isset ($oldsettings[$section])) {
2585 foreach ($oldsettings[$section] as $k => $v) {
2586 // Only copy perms for tools that have been copied
2587 if (isset ($id_mappings[$section][$k])) {
2588 $newrole->setSetting ($section,
2589 $id_mappings[$section][$k],
2597 $lm = new WidgetLayoutManager();
2598 $lm->createDefaultLayoutForProject ($this->getID(), $template->getID()) ;
2600 $params = array () ;
2601 $params['template'] = $template ;
2602 $params['project'] = $this ;
2603 $params['id_mappings'] = $id_mappings ;
2604 plugin_hook_by_reference ('clone_project_from_template', $params) ;
2606 // Disable everything
2607 $res = db_query_params ('UPDATE groups SET use_mail=0, use_survey=0, use_forum=0, use_pm=0, use_pm_depend_box=0, use_scm=0, use_news=0, use_docman=0, is_public=0, use_ftp=0, use_tracker=0, use_frs=0, use_stats=0 WHERE group_id=$1',
2609 array ($this->getID())) ;
2612 $this->normalizeAllRoles();
2614 // Switch back to user preference
2615 session_set_internal($saved_session->getID());
2616 setup_gettext_from_context();
2620 $this->sendApprovalEmail();
2621 $this->addHistory('Approved', 'x');
2624 // Plugin can make approve operation there
2626 $params[0] = $idadmin_group;
2627 $params[1] = $this->getID();
2628 plugin_hook('group_approved', $params);
2636 * sendApprovalEmail - Send new project email.
2638 * @return boolean success.
2641 function sendApprovalEmail() {
2642 $admins = RBACEngine::getInstance()->getUsersByAllowedAction ('project_admin', $this->getID()) ;
2644 if (count($admins) < 1) {
2645 $this->setError(_("Group does not have any administrators."));
2649 // send one email per admin
2650 foreach ($admins as $admin) {
2651 setup_gettext_for_user ($admin) ;
2653 $message=sprintf(_('Your project registration for %4$s has been approved.
2655 Project Full Name: %1$s
2656 Project Unix Name: %2$s
2658 Your DNS will take up to a day to become active on our site.
2659 Your web site is accessible through your shell account. Please read
2660 site documentation (see link below) about intended usage, available
2661 services, and directory layout of the account.
2664 own project page in %4$s while logged in, you will find
2665 additional menu functions to your left labeled \'Project Admin\'.
2667 We highly suggest that you now visit %4$s and create a public
2668 description for your project. This can be done by visiting your project
2669 page while logged in, and selecting \'Project Admin\' from the menus
2670 on the left (or by visiting %3$s
2673 Your project will also not appear in the Trove Software Map (primary
2674 list of projects hosted on %4$s which offers great flexibility in
2675 browsing and search) until you categorize it in the project administration
2676 screens. So that people can find your project, you should do this now.
2677 Visit your project while logged in, and select \'Project Admin\' from the
2680 Enjoy the system, and please tell others about %4$s. Let us know
2681 if there is anything we can do to help you.
2684 htmlspecialchars_decode($this->getPublicName()),
2685 $this->getUnixName(),
2686 util_make_url ('/project/admin/?group_id='.$this->getID()),
2687 forge_get_config ('forge_name'));
2689 util_send_message($admin->getEmail(), sprintf(_('%1$s Project Approved'), forge_get_config ('forge_name')), $message);
2691 setup_gettext_from_context();
2699 * sendRejectionEmail - Send project rejection email.
2701 * This function sends out a rejection message to a user who
2702 * registered a project.
2704 * @param int The id of the response to use.
2705 * @param string The rejection message.
2706 * @return boolean completion status.
2709 function sendRejectionEmail($response_id, $message="zxcv") {
2710 $submitters = array () ;
2712 foreach (get_group_join_requests ($this) as $gjr) {
2713 $submitters[] = user_get_object($gjr->getUserID());
2716 $res = db_query_params("SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND u.user_id=ug.user_id",
2718 while ($arr = db_fetch_array($res)) {
2719 $submitter[] = user_get_object($arr['user_id']);
2723 if (count ($submitters) < 1) {
2724 $this->setError(_("Group does not have any administrators."));
2728 foreach ($submitters as $admin) {
2729 setup_gettext_for_user($admin);
2731 $response=sprintf(_('Your project registration for %3$s has been denied.
2733 Project Full Name: %1$s
2734 Project Unix Name: %2$s
2736 Reasons for negative decision:
2738 '), $this->getPublicName(), $this->getUnixName(), forge_get_config('forge_name'));
2740 // Check to see if they want to send a custom rejection response
2741 if ($response_id == 0) {
2742 $response .= $message;
2744 $response .= db_result(
2745 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2750 util_send_message($admin->getEmail(), sprintf(_('%1$s Project Denied'), forge_get_config ('forge_name')), $response);
2751 setup_gettext_from_context();
2758 * sendNewProjectNotificationEmail - Send new project notification email.
2760 * This function sends out a notification email to the
2761 * SourceForge admin user when a new project is
2764 * @return boolean success.
2767 function sendNewProjectNotificationEmail() {
2768 // Get the user who wants to register the project
2769 $submitters = array();
2771 foreach (get_group_join_requests ($this) as $gjr) {
2772 $submitters[] = user_get_object($gjr->getUserID());
2775 $res = db_query_params("SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND u.user_id=ug.user_id",
2777 while ($arr = db_fetch_array ($res)) {
2778 $submitter[] = user_get_object($arr['user_id']);
2781 if (count ($submitters) < 1) {
2782 $this->setError(_("Could not find user who has submitted the project."));
2786 $admins = RBACEngine::getInstance()->getUsersByAllowedAction ('approve_projects', -1) ;
2788 if (count($admins) < 1) {
2789 $this->setError(_("There is no administrator to send the mail to."));
2793 foreach ($admins as $admin) {
2794 $admin_email = $admin->getEmail () ;
2795 setup_gettext_for_user ($admin) ;
2797 foreach ($submitters as $u) {
2798 $submitter_names[] = $u->getRealName() ;
2801 $message = sprintf(_('New %1$s Project Submitted
2803 Project Full Name: %2$s
2804 Submitted Description: %3$s
2806 forge_get_config ('forge_name'),
2807 htmlspecialchars_decode($this->getPublicName()),
2808 htmlspecialchars_decode($this->getRegistrationPurpose()));
2810 foreach ($submitters as $submitter) {
2811 $message .= sprintf(_('Submitter: %1$s (%2$s)
2813 $submitter->getRealName(),
2814 $submitter->getUnixName());
2817 $message .= sprintf (_('
2818 Please visit the following URL to approve or reject this project:
2820 util_make_url ('/admin/approve-pending.php')) ;
2821 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2822 setup_gettext_from_context();
2826 $email = $submitter->getEmail() ;
2827 setup_gettext_for_user ($submitter) ;
2829 $message=sprintf(_('New %1$s Project Submitted
2831 Project Full Name: %2$s
2832 Submitted Description: %3$s
2834 The %1$s admin team will now examine your project submission. You will be notified of their decision.'), forge_get_config ('forge_name'), $this->getPublicName(), util_unconvert_htmlspecialchars($this->getRegistrationPurpose()), forge_get_config('web_host'));
2836 util_send_message($email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2837 setup_gettext_from_context();
2846 * validateGroupName - Validate the group name
2848 * @param string Group name.
2850 * @return boolean an error false and set an error is the group name is invalide otherwise return true
2852 function validateGroupName($group_name) {
2853 if (strlen($group_name)<3) {
2854 $this->setError(_('Group name is too short'));
2856 } else if (strlen(htmlspecialchars($group_name))>50) {
2857 $this->setError(_('Group name is too long'));
2859 } else if ($group=group_get_object_by_publicname($group_name)) {
2860 $this->setError(_('Group name already taken'));
2868 * getRoles - Get the roles of the group.
2870 * @return array Role ids of this group.
2872 function getRolesId() {
2873 $role_ids = array();
2876 $res = db_query_params('SELECT role_id FROM pfo_role WHERE home_group_id=$1',
2877 array($this->getID()));
2878 while ($arr = db_fetch_array($res)) {
2879 $role_ids[] = $arr['role_id'];
2881 $res = db_query_params('SELECT role_id FROM role_project_refs WHERE group_id=$1',
2882 array($this->getID()));
2883 while ($arr = db_fetch_array($res)) {
2884 $role_ids[] = $arr['role_id'];
2887 $res = db_query_params('SELECT role_id FROM role WHERE group_id=$1',
2888 array($this->getID()));
2889 while ($arr = db_fetch_array($res)) {
2890 $role_ids[] = $arr['role_id'];
2894 return array_unique($role_ids);
2898 * getRoles - Get the roles of the group.
2900 * @return array Roles of this group.
2902 function getRoles() {
2905 $roles = $this->getRolesId();
2907 $engine = RBACEngine::getInstance();
2908 foreach ($roles as $role_id) {
2909 $result[] = $engine->getRoleById ($role_id);
2912 foreach ($roles as $role_id) {
2913 $result[] = new Role ($this, $role_id);
2920 function normalizeAllRoles() {
2921 $roles = $this->getRoles();
2923 foreach ($roles as $r) {
2924 $r->normalizeData();
2929 * getUnixStatus - Status of activation of unix account.
2931 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2933 function getUnixStatus() {
2934 return $this->data_array['unix_status'];
2938 * setUnixStatus - Sets status of activation of unix account.
2940 * @param string The unix status.
2946 * @return boolean success.
2948 function setUnixStatus($status) {
2951 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2956 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2960 if ($status == 'A') {
2961 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2962 $this->setError($SYS->getErrorMessage());
2967 if ($SYS->sysCheckGroup($this->getID())) {
2968 if (!$SYS->sysRemoveGroup($this->getID())) {
2969 $this->setError($SYS->getErrorMessage());
2976 $this->data_array['unix_status']=$status;
2983 * getUsers - Get the users of a group
2985 * @return array of user's objects.
2987 function getUsers($onlylocal = true) {
2988 if (!isset($this->membersArr)) {
2989 $this->membersArr = array () ;
2993 foreach ($this->getRoles() as $role) {
2995 && ($role->getHomeProject() == NULL || $role->getHomeProject()->getID() != $this->getID())) {
2998 foreach ($role->getUsers() as $user) {
2999 $ids[] = $user->getID() ;
3002 $ids = array_unique ($ids) ;
3003 foreach ($ids as $id) {
3004 $u = user_get_object ($id) ;
3005 if ($u->isActive()) {
3006 $this->membersArr[] = $u ;
3011 $users_group_res = db_query_params ('SELECT u.user_id FROM users u, user_group ug WHERE ug.group_id=$1 AND ug.user_id=u.user_id AND u.status=$2',
3012 array ($this->getID(),
3014 if (!$users_group_res) {
3015 $this->setError(_('Error: Enable to get users from group'). ' ' . $this->getID() . ' ' .db_error());
3019 for ($i=0; $i<db_numrows($users_group_res); $i++) {
3020 $this->membersArr[$i] = new GFUser(db_result($users_group_res,$i,'user_id'),false);
3025 return $this->membersArr;
3028 function setDocmanCreateOnlineStatus($status) {
3030 /* if we activate search engine, we probably want to reindex */
3031 $res = db_query_params('UPDATE groups SET use_docman_create_online=$1 WHERE group_id=$2',
3032 array($status, $this->getID()));
3035 $this->setError(sprintf(_('ERROR - Could Not Update Group DocmanCreateOnline Status: %s'),db_error()));
3039 $this->data_array['use_docman_create_online']=$status;
3045 function setDocmanWebdav($status) {
3047 /* if we activate search engine, we probably want to reindex */
3048 $res = db_query_params('UPDATE groups SET use_webdav=$1 WHERE group_id=$2',
3053 $this->setError(sprintf(_('ERROR - Could Not Update Group UseWebdab Status: %s'),db_error()));
3057 $this->data_array['use_webdav']=$status;
3063 function setDocmanSearchStatus($status) {
3065 /* if we activate search engine, we probably want to reindex */
3066 $res = db_query_params('UPDATE groups SET use_docman_search=$1, force_docman_reindex=$1 WHERE group_id=$2',
3071 $this->setError(sprintf(_('ERROR - Could Not Update Group UseDocmanSearch Status: %s'),db_error()));
3075 $this->data_array['use_docman_search']=$status;
3081 function setDocmanForceReindexSearch($status) {
3083 /* if we activate search engine, we probably want to reindex */
3084 $res = db_query_params('UPDATE groups SET force_docman_reindex=$1 WHERE group_id=$2',
3089 $this->setError(sprintf(_('ERROR - Could Not Update Group force_docman_reindex %s'),db_error()));
3093 $this->data_array['force_docman_reindex']=$status;
3099 function setStorageAPI($type) {
3103 function getStorageAPI() {
3109 * group_getname() - get the group name
3111 * @param int The group ID
3115 function group_getname ($group_id = 0) {
3116 $grp = group_get_object($group_id);
3118 return $grp->getPublicName();
3125 * group_getunixname() - get the unixname for a group
3127 * @param int The group ID
3131 function group_getunixname ($group_id) {
3132 $grp = group_get_object($group_id);
3134 return $grp->getUnixName();
3141 * group_get_result() - Get the group object result ID.
3143 * @param int The group ID
3147 function &group_get_result($group_id=0) {
3148 $grp = group_get_object($group_id);
3150 return $grp->getData();
3156 function getAllProjectTags($onlyvisible = true) {
3157 $res = db_query_params('SELECT project_tags.name, groups.group_id FROM groups, project_tags WHERE groups.group_id = project_tags.group_id AND groups.status = $1 ORDER BY project_tags.name, groups.group_id',
3160 if (!$res || db_numrows($res) == 0) {
3166 while ($arr = db_fetch_array($res)) {
3168 $group_id = $arr[1];
3169 if (!isset($result[$tag])) {
3170 $result[$tag] = array();
3173 if (!$only_visible || forge_check_perm('project_read', $group_id)) {
3174 $p = group_get_object($group_id);
3175 $result[$tag][] = array('unix_group_name' => $p->getUnixName(),
3176 'group_id' => $group_id);
3183 class ProjectComparator {
3184 var $criterion = 'name' ;
3186 function Compare ($a, $b) {
3187 switch ($this->criterion) {
3190 $namecmp = strcoll ($a->getPublicName(), $b->getPublicName()) ;
3191 if ($namecmp != 0) {
3194 /* If several projects share a same public name */
3195 return strcoll ($a->getUnixName(), $b->getUnixName()) ;
3198 return strcmp ($a->getUnixName(), $b->getUnixName()) ;
3201 $aid = $a->getID() ;
3202 $bid = $b->getID() ;
3206 return ($a < $b) ? -1 : 1;
3212 function sortProjectList (&$list, $criterion='name') {
3213 $cmp = new ProjectComparator () ;
3214 $cmp->criterion = $criterion ;
3216 return usort ($list, array ($cmp, 'Compare')) ;
3221 // c-file-style: "bsd"