5 * Copyright 1999-2001, VA Linux Systems, Inc.
6 * Copyright 2009-2010, Roland Mas
7 * Copyright 2010, Franck Villaume - Capgemini
8 * Copyright (C) 2010-2011 Alain Peyrat - Alcatel-Lucent
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 require_once $gfcommon.'tracker/ArtifactTypes.class.php';
27 require_once $gfcommon.'tracker/ArtifactTypeFactory.class.php';
28 require_once $gfcommon.'forum/Forum.class.php';
29 require_once $gfcommon.'forum/ForumFactory.class.php';
30 require_once $gfcommon.'pm/ProjectGroup.class.php';
31 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
32 require_once $gfcommon.'include/Role.class.php';
33 require_once $gfcommon.'frs/FRSPackage.class.php';
34 require_once $gfcommon.'docman/DocumentGroup.class.php';
35 require_once $gfcommon.'docman/DocumentGroupFactory.class.php';
36 require_once $gfcommon.'mail/MailingList.class.php';
37 require_once $gfcommon.'mail/MailingListFactory.class.php';
38 require_once $gfcommon.'survey/SurveyFactory.class.php';
39 require_once $gfcommon.'survey/SurveyQuestionFactory.class.php';
40 require_once $gfcommon.'include/gettext.php';
41 require_once $gfcommon.'include/GroupJoinRequest.class.php';
43 //the license_id of "Other/proprietary" license
44 define('GROUP_LICENSE_OTHER',126);
46 $LICENSE_NAMES=array();
49 * group_get_licences() - get the licenses list
51 * @return array list of licenses
53 function & group_get_licenses() {
54 global $LICENSE_NAMES;
55 if(empty($LICENSE_NAMES)) {
56 $result = db_query_params ('SELECT * FROM licenses', array());
57 while($data = db_fetch_array($result)) {
58 $LICENSE_NAMES[$data['license_id']] = $data['license_name'];
61 return $LICENSE_NAMES;
67 * group_get_object() - Get the group object.
69 * group_get_object() is useful so you can pool group objects/save database queries
70 * You should always use this instead of instantiating the object directly.
72 * You can now optionally pass in a db result handle. If you do, it re-uses that query
73 * to instantiate the objects.
75 * IMPORTANT! That db result must contain all fields
76 * from groups table or you will have problems
79 * @param int Result set handle ("SELECT * FROM groups WHERE group_id=xx")
80 * @return a group object or false on failure
82 function &group_get_object($group_id,$res=false) {
83 //create a common set of group objects
84 //saves a little wear on the database
86 //automatically checks group_type and
87 //returns appropriate object
90 if (!isset($GROUP_OBJ["_".$group_id."_"])) {
92 //the db result handle was passed in
94 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1', array ($group_id)) ;
96 if (!$res || db_numrows($res) < 1) {
97 $GROUP_OBJ["_".$group_id."_"]=false;
100 check group type and set up object
102 if (db_result($res,0,'type_id')==1) {
104 $GROUP_OBJ["_".$group_id."_"]= new Group($group_id,$res);
107 $GROUP_OBJ["_".$group_id."_"]=false;
111 return $GROUP_OBJ["_".$group_id."_"];
114 function &group_get_objects($id_arr) {
117 // Note: if we don't do this, the result may be corrupted
121 foreach ($id_arr as $id) {
123 // See if this ID already has been fetched in the cache
125 if (!isset($GROUP_OBJ["_".$id."_"])) {
129 if (count($fetch) > 0) {
130 $res=db_query_params ('SELECT * FROM groups WHERE group_id = ANY ($1)',
131 array (db_int_array_to_any_clause ($fetch))) ;
132 while ($arr = db_fetch_array($res)) {
133 $GROUP_OBJ["_".$arr['group_id']."_"] = new Group($arr['group_id'],$arr);
136 foreach ($id_arr as $id) {
137 $return[] =& $GROUP_OBJ["_".$id."_"];
142 function &group_get_active_projects() {
143 $res=db_query_params ('SELECT group_id FROM groups WHERE status=$1',
145 return group_get_objects (util_result_column_to_array($res,0)) ;
148 function &group_get_template_projects() {
149 $res=db_query_params ('SELECT group_id FROM groups WHERE is_template=1 AND status != $1',
151 return group_get_objects (util_result_column_to_array($res,0)) ;
154 function &group_get_object_by_name($groupname) {
155 $res=db_query_params('SELECT * FROM groups WHERE unix_group_name=$1', array ($groupname)) ;
156 return group_get_object(db_result($res,0,'group_id'),$res);
159 function &group_get_objects_by_name($groupname_arr) {
160 $res=db_query_params ('SELECT group_id FROM groups WHERE unix_group_name = ANY ($1)',
161 array (db_string_array_to_any_clause ($groupname_arr))
163 $arr =& util_result_column_to_array($res,0);
164 return group_get_objects($arr);
167 function &group_get_object_by_publicname($groupname) {
168 $res=db_query_params ('SELECT * FROM groups WHERE lower(group_name) LIKE $1',
169 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.
224 function Group($id=false, $res=false) {
227 //setting up an empty object
228 //probably going to call create()
232 if (!$this->fetchData($id)) {
237 // Assoc array was passed in
239 if (is_array($res)) {
240 $this->data_array =& $res;
242 if (db_numrows($res) < 1) {
243 //function in class we extended
244 $this->setError(_('Group Not Found'));
245 $this->data_array=array();
248 //set up an associative array for use by other functions
249 $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.
262 function fetchData($group_id) {
263 $res = db_query_params ('SELECT * FROM groups WHERE group_id=$1',
265 if (!$res || db_numrows($res) < 1) {
266 $this->setError(sprintf(_('fetchData():: %s'),db_error()));
269 $this->data_array = db_fetch_array($res);
274 * create - Create new group.
276 * This method should be called on empty Group object.
278 * @param object The User object.
279 * @param string The full name of the user.
280 * @param string The Unix name of the user.
281 * @param string The new group description.
282 * @param string The purpose of the group.
283 * @param bool Whether to send an email or not
284 * @param int The id of the project this new project is based on
286 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) {
287 // $user is ignored - anyone can create pending group
290 if ($this->getID()!=0) {
291 $this->setError(_('Group::create: Group object already exists'));
293 } else if (!$this->validateGroupName($group_name)) {
295 } else if (!account_groupnamevalid($unix_name)) {
296 $this->setError(_('Invalid Unix name'));
298 } else if (!$SYS->sysUseUnixName($unix_name)) {
299 $this->setError(_('Unix name already taken'));
301 } else if (db_numrows(db_query_params('SELECT group_id FROM groups WHERE unix_group_name=$1',
302 array ($unix_name))) > 0) {
303 $this->setError(_('Unix name already taken'));
305 } else if (strlen($purpose)<10) {
306 $this->setError(_('Please describe your Registration Purpose in a more comprehensive manner'));
308 } else if (strlen($purpose)>1500) {
309 $this->setError(_('The Registration Purpose text is too long. Please make it smaller than 1500 bytes.'));
311 } else if (strlen($description)<10) {
312 $this->setError(_('Describe in a more comprehensive manner your project.'));
314 } else if (strlen($description)>255) {
315 $this->setError(_('Your project description is too long. Please make it smaller than 256 bytes.'));
319 // Check if sys_use_project_vhost for homepage
320 if (forge_get_config('use_project_vhost')) {
321 $homepage = $unix_name.".".forge_get_config('web_host');
323 $homepage = forge_get_config('web_host')."/www/".$unix_name."/";
329 $res = db_query_params ('
345 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)',
346 array (htmlspecialchars ($group_name),
348 htmlspecialchars($description),
349 $unix_name.".".forge_get_config('web_host'),
354 htmlspecialchars($purpose),
357 md5(util_randbytes()),
358 $built_from_template)) ;
359 if (!$res || db_affected_rows($res) < 1) {
360 $this->setError(sprintf(_('ERROR: Could not create group: %s'),db_error()));
365 $id = db_insertid($res, 'groups', 'group_id');
367 $this->setError(sprintf(_('ERROR: Could not get group id: %s'),db_error()));
372 if (!$this->fetchData($id)) {
378 $gjr = new GroupJoinRequest ($this) ;
379 $gjr->create ($user->getID(),
380 'Fake GroupJoinRequest to store the creator of a project',
384 // Now, make the user an admin
386 $res=db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags,
387 cvs_flags, artifact_flags, forum_flags, role_id)
388 VALUES ($1, $2, $3, $4, $5, $6, $7)',
389 array ($user->getID(),
396 if (!$res || db_affected_rows($res) < 1) {
397 $this->setError(sprintf(_('ERROR: Could not add admin to newly created group: %s'),db_error()));
403 $hook_params = array ();
404 $hook_params['group'] = $this;
405 $hook_params['group_id'] = $this->getID();
406 $hook_params['group_name'] = $group_name;
407 $hook_params['unix_group_name'] = $unix_name;
408 plugin_hook ("group_create", $hook_params);
412 $this->sendNewProjectNotificationEmail();
420 * updateAdmin - Update core properties of group object.
422 * This function require site admin privilege.
424 * @param object User requesting operation (for access control).
425 * @param bool Whether group is publicly accessible (0/1).
426 * @param int Group type (1-project, 2-foundry).
427 * @param string Machine on which group's home directory located.
428 * @param string Domain which serves group's WWW.
432 function updateAdmin(&$user, $is_public, $type_id, $unix_box, $http_domain) {
433 $perm =& $this->getPermission ();
435 if (!$perm || !is_object($perm)) {
436 $this->setError(_('Could not get permission.'));
440 if (!$perm->isSuperUser()) {
441 $this->setError(_('Permission denied.'));
447 $res = db_query_params ('
450 unix_box=$2, http_domain=$3
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 ($type_id != $this->data_array['type_id']) {
465 $this->addHistory('type_id', $this->data_array['type_id']);
467 if ($unix_box != $this->data_array['unix_box']) {
468 $this->addHistory('unix_box', $this->data_array['unix_box']);
470 if ($http_domain != $this->data_array['http_domain']) {
471 $this->addHistory('http_domain', $this->data_array['http_domain']);
474 if (!$this->fetchData($this->getID())) {
483 * update - Update number of common properties.
485 * Unlike updateAdmin(), this function accessible to project admin.
487 * @param object User requesting operation (for access control).
488 * @param bool Whether group is publicly accessible (0/1).
489 * @param string Project's license (string ident).
490 * @param int Group type (1-project, 2-foundry).
491 * @param string Machine on which group's home directory located.
492 * @param string Domain which serves group's WWW.
493 * @return int status.
496 function update(&$user, $group_name,$homepage,$short_description,$use_mail,$use_survey,$use_forum,
497 $use_pm,$use_pm_depend_box,$use_scm,$use_news,$use_docman,
498 $new_doc_address,$send_all_docs,$logo_image_id,
499 $use_ftp,$use_tracker,$use_frs,$use_stats,$tags,$is_public) {
501 $perm =& $this->getPermission ();
503 if (!$perm || !is_object($perm)) {
504 $this->setError(_('Could not get permission.'));
508 if (!$perm->isAdmin()) {
509 $this->setError(_('Permission denied.'));
513 // Validate some values
514 if ($this->getPublicName() != $group_name) {
515 if (!$this->validateGroupName($group_name)) {
520 if ($new_doc_address) {
521 $invalid_mails = validate_emails($new_doc_address);
522 if (count($invalid_mails) > 0) {
523 $this->setError(sprintf (ngettext('New Doc Address Appeared Invalid: %s', 'New Doc Addresses Appeared Invalid: %s', count($invalid_mails)),implode(',',$invalid_mails)));
528 // in the database, these all default to '1',
529 // so we have to explicity set 0
542 if (!$use_pm_depend_box) {
543 $use_pm_depend_box=0;
566 if (!$send_all_docs) {
570 $homepage = ltrim($homepage);
572 $homepage=util_make_url('/projects/' . $this->getUnixName() . '/');
575 if (strlen(htmlspecialchars($short_description))>255) {
576 $this->setError(_('Error updating project information: Maximum length for Project Description is 255 chars.'));
582 //XXX not yet actived logo_image_id='$logo_image_id',
583 $res = db_query_params ('UPDATE groups
586 short_description=$3,
591 use_pm_depend_box=$8,
602 array (htmlspecialchars($group_name),
604 htmlspecialchars($short_description),
622 $this->setError(sprintf(_('Error updating project information: %s'), db_error()));
627 if ($this->setTags($tags) === false) {
632 $hook_params = array ();
633 $hook_params['group'] = $this;
634 $hook_params['group_id'] = $this->getID();
635 $hook_params['group_homepage'] = $homepage;
636 $hook_params['group_name'] = htmlspecialchars($group_name);
637 $hook_params['group_description'] = htmlspecialchars($short_description);
638 plugin_hook ("group_update", $hook_params);
640 // Log the audit trail
641 $this->addHistory('Changed Public Info', '');
643 if (!$this->fetchData($this->getID())) {
652 * getID - Simply return the group_id for this object.
654 * @return int group_id.
657 return $this->data_array['group_id'];
661 * getType() - Foundry, project, etc.
663 * @return int The type flag from the database.
666 return $this->data_array['type_id'];
671 * getStatus - the status code.
673 * Statuses char include I,H,A,D.
675 function getStatus() {
676 return $this->data_array['status'];
680 * setStatus - set the status code.
682 * Statuses include I,H,A,D.
684 * @param object User requesting operation (for access control).
685 * @param string Status value.
686 * @return boolean success.
689 function setStatus(&$user, $status) {
692 if (!forge_check_global_perm ('approve_projects')) {
693 $this->setPermissionDeniedError();
697 // Projects in 'A' status can only go to 'H' or 'D'
698 // Projects in 'D' status can only go to 'A'
699 // Projects in 'P' status can only go to 'A' OR 'D'
700 // Projects in 'I' status can only go to 'P'
701 // Projects in 'H' status can only go to 'A' OR 'D'
702 $allowed_status_changes = array(
703 'AH'=>1,'AD'=>1,'DA'=>1,'PA'=>1,'PD'=>1,
704 'IP'=>1,'HA'=>1,'HD'=>1
707 // Check that status transition is valid
708 if ($this->getStatus() != $status
709 && !$allowed_status_changes[$this->getStatus().$status]) {
710 $this->setError(_('Invalid Status Change'));
716 $res = db_query_params ('UPDATE groups
718 WHERE group_id=$2', array ($status, $this->getID())) ;
720 if (!$res || db_affected_rows($res) < 1) {
721 $this->setError(sprintf(_('ERROR: DB: Could not change group status: %s'),db_error()));
727 // Activate system group, if not yet
728 if (!$SYS->sysCheckGroup($this->getID())) {
729 if (!$SYS->sysCreateGroup($this->getID())) {
730 $this->setError($SYS->getErrorMessage());
735 if (!$this->activateUsers()) {
740 /* Otherwise, the group is not active, and make sure that
741 System group is not active either */
742 } else if ($SYS->sysCheckGroup($this->getID())) {
743 if (!$SYS->sysRemoveGroup($this->getID())) {
744 $this->setError($SYS->getErrorMessage());
750 $hook_params = array ();
751 $hook_params['group'] = $this;
752 $hook_params['group_id'] = $this->getID();
753 $hook_params['status'] = $status;
754 plugin_hook ("group_setstatus", $hook_params);
758 // Log the audit trail
759 if ($status != $this->getStatus()) {
760 $this->addHistory('Status', $this->getStatus());
763 $this->data_array['status'] = $status;
768 * isProject - Simple boolean test to see if it's a project or not.
770 * @return boolean is_project.
772 function isProject() {
773 if ($this->getType()==1) {
781 * isPublic - Wrapper around RBAC to check if a project is anonymously readable
783 * @return boolean is_public.
785 function isPublic() {
786 $ra = RoleAnonymous::getInstance() ;
787 return $ra->hasPermission('project_read', $this->getID());
791 * isActive - Database field status of 'A' returns true.
793 * @return boolean is_active.
795 function isActive() {
796 if ($this->getStatus()=='A') {
804 * isTemplate - Simply returns the is_template flag from the database.
806 * @return boolean is_template.
808 function isTemplate() {
809 return $this->data_array['is_template'];
813 * setAsTemplate - Set the template status of a project
815 * @param boolean is_template.
817 function setAsTemplate ($booleanparam) {
819 $booleanparam = $booleanparam ? 1 : 0 ;
820 $res = db_query_params ('UPDATE groups SET is_template=$1 WHERE group_id=$2',
821 array ($booleanparam, $this->getID()));
823 $this->data_array['is_template']=$booleanparam;
833 * getTemplateProject - Return the project template this project is built from
835 * @return object The template project
837 function getTemplateProject() {
838 return group_get_object($this->data_array['built_from_template']);
842 * getUnixName - the unix_name
844 * @return string unix_name.
846 function getUnixName() {
847 return strtolower($this->data_array['unix_group_name']);
851 * getPublicName - the full-length public name.
853 * @return string The group_name.
855 function getPublicName() {
856 return $this->data_array['group_name'];
860 * getRegisterPurpose - the text description of the purpose of this project.
862 * @return string The description.
864 function getRegisterPurpose() {
865 return $this->data_array['register_purpose'];
869 * getDescription - the text description of this project.
871 * @return string The description.
873 function getDescription() {
874 return $this->data_array['short_description'];
878 * getStartDate - the unix time this project was registered.
880 * @return int (unix time) of registration.
882 function getStartDate() {
883 return $this->data_array['register_time'];
887 * getLogoImageID - the id of the logo in the database for this project.
889 * @return int The ID of logo image in db_images table (or 100 if none).
891 function getLogoImageID() {
892 return $this->data_array['logo_image_id'];
896 * getUnixBox - the hostname of the unix box where this project is located.
898 * @return string The name of the unix machine for the group.
900 function getUnixBox() {
901 return $this->data_array['unix_box'];
905 * getSCMBox - the hostname of the scm box where this project is located.
907 * @return string The name of the unix machine for the group.
909 function getSCMBox() {
910 return $this->data_array['scm_box'];
913 * setSCMBox - the hostname of the scm box where this project is located.
915 * @param string The name of the new SCM_BOX
917 function setSCMBox($scm_box) {
919 if ($scm_box == $this->data_array['scm_box']) {
924 $res = db_query_params ('UPDATE groups SET scm_box=$1 WHERE group_id=$2', array ($scm_box, $this->getID ()));
926 $this->addHistory('scm_box', $this->data_array['scm_box']);
927 $this->data_array['scm_box']=$scm_box;
932 $this->setError(_("Couldn't insert SCM_BOX to database"));
936 $this->setError(_("SCM Box can't be empty"));
942 * getDomain - the hostname.domain where their web page is located.
944 * @return string The name of the group [web] domain.
946 function getDomain() {
947 return $this->data_array['http_domain'];
951 * getLicense - the license they chose.
953 * @return int ident of group license.
955 function getLicense() {
956 return $this->data_array['license'];
960 * getLicenseName - the name of the license
962 * @return string license name
964 function getLicenseName() {
965 $licenses =& group_get_licenses();
966 if(isset($licenses[$this->data_array['license']])) {
967 return $licenses[$this->data_array['license']];
974 * getLicenseOther - optional string describing license.
976 * @return string The custom license.
978 function getLicenseOther() {
979 if ($this->getLicense() == GROUP_LICENSE_OTHER) {
980 return $this->data_array['license_other'];
987 * getRegistrationPurpose - the text description of the purpose of this project.
989 * @return string The application for project hosting.
991 function getRegistrationPurpose() {
992 return $this->data_array['register_purpose'];
997 * getAdmins() - Get array of Admin user objects.
999 * @return array Array of User objects.
1001 function &getAdmins() {
1002 $roles = RBACEngine::getInstance()->getRolesByAllowedAction ('project_admin', $this->getID()) ;
1004 $user_ids = array () ;
1006 foreach ($roles as $role) {
1007 if (! ($role instanceof RoleExplicit)) {
1010 if ($role->getHomeProject() == NULL
1011 || $role->getHomeProject()->getID() != $this->getID()) {
1015 foreach ($role->getUsers() as $u) {
1016 $user_ids[] = $u->getID() ;
1020 return user_get_objects(array_unique($user_ids));
1025 Common Group preferences for tools
1030 * enableAnonSCM - whether or not this group has opted to enable Anonymous SCM.
1032 * @return boolean enable_scm.
1034 function enableAnonSCM() {
1036 $r = RoleAnonymous::getInstance () ;
1037 return $r->hasPermission ('scm', $this->getID(), 'read') ;
1039 if ($this->isPublic() && $this->usesSCM()) {
1040 return $this->data_array['enable_anonscm'];
1047 function SetUsesAnonSCM ($booleanparam) {
1049 $booleanparam = $booleanparam ? 1 : 0 ;
1051 $r = RoleAnonymous::getInstance () ;
1052 $r->setSetting ('scm', $this->getID(), $booleanparam) ;
1055 $res = db_query_params ('UPDATE groups SET enable_anonscm=$1 WHERE group_id=$2',
1056 array ($booleanparam, $this->getID()));
1058 $this->data_array['enable_anonscm']=$booleanparam;
1067 function setUsesSCM ($booleanparam) {
1069 $booleanparam = $booleanparam ? 1 : 0 ;
1070 $res = db_query_params ('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
1071 array ($booleanparam, $this->getID()));
1073 $this->data_array['use_scm']=$booleanparam;
1082 * enablePserver - whether or not this group has opted to enable Pserver.
1084 * @return boolean enable_pserver.
1086 function enablePserver() {
1087 if ($this->usesSCM()) {
1088 return $this->data_array['enable_pserver'];
1094 function SetUsesPserver ($booleanparam) {
1096 $booleanparam = $booleanparam ? 1 : 0 ;
1097 $res = db_query_params ('UPDATE groups SET enable_pserver=$1 WHERE group_id=$2',
1098 array ($booleanparam, $this->getID()));
1100 $this->data_array['enable_pserver']=$booleanparam;
1109 * usesSCM - whether or not this group has opted to use SCM.
1111 * @return boolean uses_scm.
1113 function usesSCM() {
1115 if (forge_get_config('use_scm')) {
1116 return $this->data_array['use_scm'];
1123 * setUseSCM - Set the SCM usage
1125 * @param boolean enabled/disabled
1127 function setUseSCM ($booleanparam) {
1129 $booleanparam = $booleanparam ? 1 : 0 ;
1130 $res = db_query_params ('UPDATE groups SET use_scm=$1 WHERE group_id=$2',
1131 array ($booleanparam, $this->getID()));
1133 $this->data_array['use_scm']=$booleanparam;
1143 * usesMail - whether or not this group has opted to use mailing lists.
1145 * @return boolean uses_mail.
1147 function usesMail() {
1149 if (forge_get_config('use_mail')) {
1150 return $this->data_array['use_mail'];
1157 * setUseMail - Set the mailing-list usage
1159 * @param boolean enabled/disabled
1161 function setUseMail ($booleanparam) {
1163 $booleanparam = $booleanparam ? 1 : 0 ;
1164 $res = db_query_params ('UPDATE groups SET use_mail=$1 WHERE group_id=$2',
1165 array ($booleanparam, $this->getID()));
1167 $this->data_array['use_mail']=$booleanparam;
1177 * usesNews - whether or not this group has opted to use news.
1179 * @return boolean uses_news.
1181 function usesNews() {
1183 if (forge_get_config('use_news')) {
1184 return $this->data_array['use_news'];
1191 * usesForum - whether or not this group has opted to use discussion forums.
1193 * @return boolean uses_forum.
1195 function usesForum() {
1197 if (forge_get_config('use_forum')) {
1198 return $this->data_array['use_forum'];
1205 * setUseForum - Set the forum usage
1207 * @param boolean enabled/disabled
1209 function setUseForum ($booleanparam) {
1211 $booleanparam = $booleanparam ? 1 : 0 ;
1212 $res = db_query_params ('UPDATE groups SET use_forum=$1 WHERE group_id=$2',
1213 array ($booleanparam, $this->getID()));
1215 $this->data_array['use_forum']=$booleanparam;
1225 * usesStats - whether or not this group has opted to use stats.
1227 * @return boolean uses_stats.
1229 function usesStats() {
1230 return $this->data_array['use_stats'];
1234 * usesFRS - whether or not this group has opted to use file release system.
1236 * @return boolean uses_frs.
1238 function usesFRS() {
1240 if (forge_get_config('use_frs')) {
1241 return $this->data_array['use_frs'];
1248 * setUseFRS - Set the FRS usage
1250 * @param boolean enabled/disabled
1252 function setUseFRS ($booleanparam) {
1254 $booleanparam = $booleanparam ? 1 : 0 ;
1255 $res = db_query_params ('UPDATE groups SET use_frs=$1 WHERE group_id=$2',
1256 array ($booleanparam, $this->getID()));
1258 $this->data_array['use_frs']=$booleanparam;
1268 * usesTracker - whether or not this group has opted to use tracker.
1270 * @return boolean uses_tracker.
1272 function usesTracker() {
1274 if (forge_get_config('use_tracker')) {
1275 return $this->data_array['use_tracker'];
1282 * setUseTracker - Set the tracker usage
1284 * @param boolean enabled/disabled
1286 function setUseTracker ($booleanparam) {
1288 $booleanparam = $booleanparam ? 1 : 0 ;
1289 $res = db_query_params ('UPDATE groups SET use_tracker=$1 WHERE group_id=$2',
1290 array ($booleanparam, $this->getID()));
1292 $this->data_array['use_tracker']=$booleanparam;
1302 * useCreateOnline - whether or not this group has opted to use create online documents option.
1304 * @return boolean use_docman_create_online.
1306 function useCreateOnline() {
1308 if (forge_get_config('use_docman')) {
1309 return $this->data_array['use_docman_create_online'];
1316 * usesDocman - whether or not this group has opted to use docman.
1318 * @return boolean use_docman.
1320 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() {
1356 if (forge_get_config('use_docman')) {
1357 return $this->data_array['use_docman_search'];
1364 * useWebdav - whether or not this group has opted to use webdav interface.
1366 * @return boolean use_docman_search.
1368 function useWebdav() {
1370 if (forge_get_config('use_webdav')) {
1371 return $this->data_array['use_webdav'];
1378 * usesFTP - whether or not this group has opted to use FTP.
1380 * @return boolean uses_ftp.
1382 function usesFTP() {
1384 if (forge_get_config('use_ftp')) {
1385 return $this->data_array['use_ftp'];
1392 * usesSurvey - whether or not this group has opted to use surveys.
1394 * @return boolean uses_survey.
1396 function usesSurvey() {
1398 if (forge_get_config('use_survey')) {
1399 return $this->data_array['use_survey'];
1406 * usesPM - whether or not this group has opted to Project Manager.
1408 * @return boolean uses_projman.
1412 if (forge_get_config('use_pm')) {
1413 return $this->data_array['use_pm'];
1420 * setUsePM - Set the PM usage
1422 * @param boolean enabled/disabled
1424 function setUsePM ($booleanparam) {
1426 $booleanparam = $booleanparam ? 1 : 0 ;
1427 $res = db_query_params ('UPDATE groups SET use_pm=$1 WHERE group_id=$2',
1428 array ($booleanparam, $this->getID()));
1430 $this->data_array['use_pm']=$booleanparam;
1440 * getPlugins - get a list of all available group plugins
1442 * @return array array containing plugin_id => plugin_name
1444 function getPlugins() {
1445 if (!isset($this->plugins_data)) {
1446 $this->plugins_data = array () ;
1447 $res = db_query_params ('SELECT group_plugin.plugin_id, plugins.plugin_name
1448 FROM group_plugin, plugins
1449 WHERE group_plugin.group_id=$1
1450 AND group_plugin.plugin_id=plugins.plugin_id', array ($this->getID()));
1451 $rows = db_numrows($res);
1453 for ($i=0; $i<$rows; $i++) {
1454 $plugin_id = db_result($res,$i,'plugin_id');
1455 $this->plugins_data[$plugin_id] = db_result($res,$i,'plugin_name');
1458 return $this->plugins_data ;
1462 * usesPlugin - returns true if the group uses a particular plugin
1464 * @param string name of the plugin
1465 * @return boolean whether plugin is being used or not
1467 function usesPlugin($pluginname) {
1468 $plugins_data = $this->getPlugins() ;
1469 foreach ($plugins_data as $p_id => $p_name) {
1470 if ($p_name == $pluginname) {
1477 * added for Codendi compatibility
1478 * usesServices - returns true if the group uses a particular plugin or feature
1480 * @param string name of the plugin
1481 * @return boolean whether plugin is being used or not
1483 function usesService($feature) {
1484 $plugins_data = $this->getPlugins() ;
1485 $pm = plugin_manager_get_object();
1486 foreach ($plugins_data as $p_id => $p_name) {
1487 if ($p_name == $feature) {
1490 if ($pm->getPluginByName($p_name)->provide($feature) ) {
1498 * setPluginUse - enables/disables plugins for the group
1500 * @param string name of the plugin
1501 * @param boolean the new state
1502 * @return string database result
1504 function setPluginUse($pluginname, $val=true) {
1505 if ($val == $this->usesPlugin($pluginname)) {
1506 // State is already good, returning
1509 $res = db_query_params ('SELECT plugin_id FROM plugins WHERE plugin_name=$1',
1510 array ($pluginname));
1511 $rows = db_numrows($res);
1513 // Error: no plugin by that name
1516 $plugin_id = db_result($res,0,'plugin_id');
1518 unset ($this->plugins_data) ;
1520 $res = db_query_params ('INSERT INTO group_plugin (group_id, plugin_id) VALUES ($1, $2)',
1521 array ($this->getID(),
1525 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1 AND plugin_id=$2',
1526 array ($this->getID(),
1533 * getDocEmailAddress - get email address(es) to send doc notifications to.
1535 * @return string email address.
1537 function getDocEmailAddress() {
1538 return $this->data_array['new_doc_address'];
1542 * DocEmailAll - whether or not this group has opted to use receive notices on all doc updates.
1544 * @return boolean email_on_all_doc_updates.
1546 function docEmailAll() {
1547 return $this->data_array['send_all_docs'];
1552 * getHomePage - The URL for this project's home page.
1554 * @return string homepage URL.
1556 function getHomePage() {
1557 return $this->data_array['homepage'];
1561 * getTags - Tags of this project.
1563 * @return string List of tags.
1565 function getTags() {
1566 $sql = 'SELECT name FROM project_tags WHERE group_id = $1';
1567 $res = db_query_params($sql, array($this->getID()));
1568 return join(', ', util_result_column_to_array($res));
1572 * setTags - Set tags of this project.
1574 * @return string database result.
1576 function setTags($tags) {
1578 $sql='DELETE FROM project_tags WHERE group_id=$1';
1579 $res=db_query_params($sql, array($this->getID()));
1581 $this->setError('Deleting old tags: '.db_error());
1585 $inserted = array();
1586 $tags_array = preg_split('/[;,]/', $tags);
1587 foreach ($tags_array as $tag) {
1588 $tag = preg_replace('/[\t\r\n]/', ' ', $tag);
1589 // Allowed caracteres: [A-Z][a-z][0-9] -_&'#+.
1590 if (preg_match('/[^[:alnum:]| |\-|_|\&|\'|#|\+|\.]/', $tag)) {
1591 $this->setError(_('Bad tag name, you only can use the following characters: [A-Z][a-z][0-9]-_&\'#+. and space'));
1596 if ($tag == '' || array_search($tag, $inserted) !== false) continue;
1597 $sql='INSERT INTO project_tags (group_id,name) VALUES ($1, $2)';
1598 $res=db_query_params($sql, array($this->getID(), $tag));
1600 $this->setError(_('Setting tags: ').db_error());
1611 * getPermission - Return a Permission for this Group
1613 * @return object The Permission.
1615 function &getPermission() {
1616 return permission_get_object($this);
1620 function delete($sure,$really_sure,$really_really_sure) {
1621 if (!$sure || !$really_sure || !$really_really_sure) {
1622 $this->setMissingParamsError(_('Please tick all checkboxes.'));
1625 if ($this->getID() == forge_get_config('news_group') ||
1626 $this->getID() == 1 ||
1627 $this->getID() == forge_get_config('stats_group') ||
1628 $this->getID() == forge_get_config('peer_rating_group')) {
1629 $this->setError(_('Cannot Delete System Group'));
1632 $perm =& $this->getPermission ();
1633 if (!$perm || !is_object($perm)) {
1634 $this->setPermissionDeniedError();
1636 } elseif ($perm->isError()) {
1637 $this->setPermissionDeniedError();
1639 } elseif (!$perm->isSuperUser()) {
1640 $this->setPermissionDeniedError();
1646 // Remove all the members
1648 $members =& $this->getMembers();
1649 foreach ($members as $i) {
1650 $this->removeUser($i->getID());
1652 // Failsafe until user_group table is gone
1653 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1',
1654 array ($this->getID())) ;
1656 // unlink roles from this project
1657 $ra = RoleAnonymous::getInstance();
1658 $rl = RoleLoggedIn::getInstance();
1659 $ra->unlinkProject($this);
1660 $rl->unlinkProject($this);
1661 // @todo : unlink all the other roles created in the project...
1666 $atf = new ArtifactTypeFactory($this);
1667 $at_arr =& $atf->getArtifactTypes();
1668 foreach ($at_arr as $i) {
1669 if (!is_object($i)) {
1677 $ff = new ForumFactory($this);
1678 $f_arr =& $ff->getForums();
1679 foreach ($f_arr as $i) {
1680 if (!is_object($i)) {
1686 // Delete Subprojects
1688 $pgf = new ProjectGroupFactory($this);
1689 $pg_arr =& $pgf->getProjectGroups();
1690 foreach ($pg_arr as $i) {
1691 if (!is_object($i)) {
1697 // Delete FRS Packages
1699 //$frspf = new FRSPackageFactory($this);
1700 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1701 array ($this->getID())) ;
1702 //echo 'frs_package'.db_error();
1703 //$frsp_arr =& $frspf->getPackages();
1704 while ($arr = db_fetch_array($res)) {
1705 //if (!is_object($pg_arr[$i])) {
1706 // echo "Not Object: ProjectGroup: ".$i;
1709 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1715 $news_group=group_get_object(forge_get_config('news_group'));
1716 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1717 array ($this->getID())) ;
1719 $this->setError(_('Error Deleting News: ').db_error());
1724 for ($i=0; $i<db_numrows($res); $i++) {
1725 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1726 if (!$Forum->delete(1,1)) {
1727 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1730 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1731 array ($this->getID())) ;
1733 $this->setError(_('Error Deleting News: ').db_error());
1741 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1742 array ($this->getID())) ;
1744 $this->setError(_('Error Deleting Documents: ').db_error());
1749 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1750 array ($this->getID())) ;
1752 $this->setError(_('Error Deleting Documents: ').db_error());
1760 $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
1762 $this->setError(_('Error Deleting Tags: ').db_error());
1768 // Delete group history
1770 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1771 array ($this->getID())) ;
1773 $this->setError(_('Error Deleting Project History: ').db_error());
1779 // Delete group plugins
1781 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1782 array ($this->getID())) ;
1784 $this->setError(_('Error Deleting Project Plugins: ').db_error());
1790 // Delete group cvs stats
1792 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1793 array ($this->getID())) ;
1795 $this->setError(_('Error Deleting SCM Statistics: ').db_error());
1803 $sf = new SurveyFactory($this);
1804 $s_arr =& $sf->getSurveys();
1805 foreach ($s_arr as $i) {
1806 if (!is_object($i)) {
1809 if (!$i->delete()) {
1810 $this->setError(_('Could not properly delete the survey'));
1816 // Delete SurveyQuestions
1818 $sqf = new SurveyQuestionFactory($this);
1819 $sq_arr =& $sqf->getSurveyQuestions();
1820 foreach ($sq_arr as $i) {
1821 if (!is_object($i)) {
1824 if (!$i->delete()) {
1825 $this->setError(_('Could not properly delete the survey questions'));
1831 // Delete Mailing List Factory
1833 $mlf = new MailingListFactory($this);
1834 $ml_arr = $mlf->getMailingLists();
1835 foreach ($ml_arr as $i) {
1836 if (!is_object($i)) {
1839 if (!$i->delete(1,1)) {
1840 $this->setError(_('Could not properly delete the mailing list'));
1848 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1849 array ($this->getID())) ;
1851 $this->setError(_('Error Deleting Trove: ').db_error());
1856 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1857 array ($this->getID())) ;
1859 $this->setError(_('Error Deleting Trove: ').db_error());
1867 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1868 array ($this->getID())) ;
1870 $this->setError(_('Error Deleting Counters: ').db_error());
1875 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1876 array ($this->getUnixName(),
1880 $this->setError(_('Error Deleting Project:').' '.db_error());
1885 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1886 array ($this->getID())) ;
1888 $this->setError(_('Error Deleting Project:').' '.db_error());
1898 $hook_params = array ();
1899 $hook_params['group'] = $this;
1900 $hook_params['group_id'] = $this->getID();
1901 plugin_hook ("group_delete", $hook_params);
1903 if (forge_get_config('upload_dir') != '' && $this->getUnixName()) {
1904 exec('/bin/rm -rf '.forge_get_config('upload_dir').'/'.$this->getUnixName().'/');
1906 if (forge_get_config('ftp_upload_dir') != '' && $this->getUnixName()) {
1907 exec('/bin/rm -rf '.forge_get_config('ftp_upload_dir').'/'.$this->getUnixName().'/');
1912 $res = db_query_params ('DELETE FROM rep_group_act_monthly WHERE group_id=$1',
1913 array ($this->getID())) ;
1914 //echo 'rep_group_act_monthly'.db_error();
1915 $res = db_query_params ('DELETE FROM rep_group_act_weekly WHERE group_id=$1',
1916 array ($this->getID())) ;
1917 //echo 'rep_group_act_weekly'.db_error();
1918 $res = db_query_params ('DELETE FROM rep_group_act_daily WHERE group_id=$1',
1919 array ($this->getID())) ;
1920 //echo 'rep_group_act_daily'.db_error();
1921 unset($this->data_array);
1929 Basic functions to add/remove users to/from a group
1930 and update their permissions
1936 * addUser - controls adding a user to a group.
1938 * @param string Unix name of the user to add OR integer user_id.
1939 * @param int The role_id this user should have.
1940 * @return boolean success.
1943 function addUser($user_identifier,$role_id) {
1946 Admins can add users to groups
1949 if (!forge_check_perm ('project_admin', $this->getID())) {
1950 $this->setPermissionDeniedError();
1956 get user id for this user's unix_name
1958 if (is_int ($user_identifier)) { // user_id or user_name
1959 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1961 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1963 if (db_numrows($res_newuser) > 0) {
1965 // make sure user is active
1967 if (db_result($res_newuser,0,'status') != 'A') {
1968 $this->setError(_('User is not active. Only active users can be added.'));
1974 // user was found - set new user_id var
1976 $user_id = db_result($res_newuser,0,'user_id');
1978 $role = new Role($this,$role_id);
1979 if (!$role || !is_object($role)) {
1980 $this->setError(_('Error Getting Role Object'));
1983 } elseif ($role->isError()) {
1984 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1990 $role->addUser (user_get_object ($user_id)) ;
1991 if (!$SYS->sysCheckCreateGroup($this->getID())){
1992 $this->setError($SYS->getErrorMessage());
1996 if (!$SYS->sysCheckCreateUser($user_id)) {
1997 $this->setError($SYS->getErrorMessage());
2001 if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
2002 $this->setError($SYS->getErrorMessage());
2009 // if not already a member, add them
2011 $res_member = db_query_params ('SELECT user_id
2013 WHERE user_id=$1 AND group_id=$2',
2014 array ($user_id, $this->getID())) ;
2016 if (db_numrows($res_member) < 1) {
2018 // Create this user's row in the user_group table
2020 $res = db_query_params ('INSERT INTO user_group
2021 (user_id,group_id,admin_flags,forum_flags,project_flags,
2022 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
2023 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
2035 //verify the insert worked
2036 if (!$res || db_affected_rows($res) < 1) {
2037 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
2042 // check and create if group doesn't exists
2044 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
2045 if (!$SYS->sysCheckCreateGroup($this->getID())){
2046 $this->setError($SYS->getErrorMessage());
2051 // check and create if user doesn't exists
2053 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
2054 if (!$SYS->sysCheckCreateUser($user_id)) {
2055 $this->setError($SYS->getErrorMessage());
2062 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
2063 if (!$role->setUser($user_id)) {
2064 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
2070 // user was already a member
2071 // make sure they are set up
2073 $user= user_get_object($user_id,$res_newuser);
2074 $user->fetchData($user->getID());
2075 $role = new Role($this,$role_id);
2076 if (!$role || !is_object($role)) {
2077 $this->setError(_('Error Getting Role Object'));
2080 } elseif ($role->isError()) {
2081 $this->setError('addUser::roleget::'.$role->getErrorMessage());
2085 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
2086 if (!$role->setUser($user_id)) {
2087 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
2092 // set up their system info
2094 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
2095 if (!$SYS->sysCheckCreateUser($user_id)) {
2096 $this->setError($SYS->getErrorMessage());
2104 // user doesn't exist
2106 $this->setError(_('ERROR: User does not exist'));
2111 $hook_params['group'] = $this;
2112 $hook_params['group_id'] = $this->getID();
2113 $hook_params['user'] = &user_get_object($user_id);
2114 $hook_params['user_id'] = $user_id;
2115 plugin_hook ("group_adduser", $hook_params);
2120 $this->addHistory('Added User',$user_identifier);
2126 * removeUser - controls removing a user from a group.
2128 * Users can remove themselves.
2130 * @param int The ID of the user to remove.
2131 * @return boolean success.
2133 function removeUser($user_id) {
2136 if ($user_id != user_getid()
2137 && !forge_check_perm ('project_admin', $this->getID())) {
2138 $this->setPermissionDeniedError();
2145 $user = user_get_object ($user_id) ;
2146 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
2147 $found_role = NULL ;
2148 foreach ($roles as $role) {
2149 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2150 $found_role = $role ;
2154 if ($found_role == NULL) {
2155 $this->setError(sprintf(_('ERROR: User not removed: %s')));
2159 $found_role->removeUser ($user) ;
2160 if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
2161 $this->setError($SYS->getErrorMessage());
2167 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
2168 array ($this->getID(),
2170 if (!$res || db_affected_rows($res) < 1) {
2171 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
2178 // reassign open artifacts to id=100
2180 $res = db_query_params ('UPDATE artifact SET assigned_to=100
2181 WHERE group_artifact_id
2182 IN (SELECT group_artifact_id
2183 FROM artifact_group_list
2184 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
2185 array ($this->getID(),
2188 $this->setError(_('ERROR: DB: artifact:').' '.db_error());
2194 // reassign open tasks to id=100
2195 // first have to purge any assignments that would cause
2196 // conflict with existing assignment to 100
2198 $res = db_query_params ('DELETE FROM project_assigned_to
2199 WHERE project_task_id IN (SELECT pt.project_task_id
2200 FROM project_task pt, project_group_list pgl, project_assigned_to pat
2201 WHERE pt.group_project_id = pgl.group_project_id
2202 AND pat.project_task_id=pt.project_task_id
2203 AND pt.status_id=1 AND pgl.group_id=$1
2204 AND pat.assigned_to_id=$2)
2205 AND assigned_to_id=100',
2206 array ($this->getID(),
2209 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
2213 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
2214 WHERE project_task_id IN (SELECT pt.project_task_id
2215 FROM project_task pt, project_group_list pgl
2216 WHERE pt.group_project_id = pgl.group_project_id
2217 AND pt.status_id=1 AND pgl.group_id=$1)
2218 AND assigned_to_id=$2',
2219 array ($this->getID(),
2222 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
2228 // Remove user from system
2230 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
2231 $this->setError($SYS->getErrorMessage());
2236 $hook_params['group'] = $this;
2237 $hook_params['group_id'] = $this->getID();
2238 $hook_params['user'] = user_get_object($user_id);
2239 $hook_params['user_id'] = $user_id;
2240 plugin_hook ("group_removeuser", $hook_params);
2243 $this->addHistory('Removed User',$user_id);
2250 * updateUser - controls updating a user's role in this group.
2252 * @param int The ID of the user.
2253 * @param int The role_id to set this user to.
2254 * @return boolean success.
2256 function updateUser($user_id,$role_id) {
2259 if (!forge_check_perm ('project_admin', $this->getID())) {
2260 $this->setPermissionDeniedError();
2265 $newrole = RBACEngine::getInstance()->getRoleById ($role_id) ;
2266 if (!$newrole || !is_object($newrole)) {
2267 $this->setError(_('Could Not Get Role'));
2269 } elseif ($newrole->isError()) {
2270 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2272 } elseif ($newrole->getHomeProject() == NULL
2273 || $newrole->getHomeProject()->getID() != $this->getID()) {
2274 $this->setError(_('Wrong destination role'));
2277 $user = user_get_object ($user_id) ;
2278 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
2279 $found_role = NULL ;
2280 foreach ($roles as $role) {
2281 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2282 $found_role = $role ;
2286 if ($found_role == NULL) {
2287 $this->setError(sprintf(_('ERROR: User not removed: %s')));
2291 $found_role->removeUser ($user) ;
2292 $newrole->addUser ($user) ;
2294 $role = new Role($this,$role_id);
2295 if (!$role || !is_object($role)) {
2296 $this->setError(_('Could Not Get Role'));
2298 } elseif ($role->isError()) {
2299 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2302 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
2303 if (!$role->setUser($user_id)) {
2304 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2309 $this->addHistory('Updated User',$user_id);
2314 * addHistory - Makes an audit trail entry for this project.
2316 * @param string The name of the field.
2317 * @param string The Old Value for this $field_name.
2318 * @return database result handle.
2321 function addHistory($field_name, $old_value) {
2322 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
2323 VALUES ($1,$2,$3,$4,$5)',
2324 array ($this->getID(),
2332 * activateUsers - Make sure that group members have unix accounts.
2334 * Setup unix accounts for group members. Can be called even
2335 * if members are already active.
2339 function activateUsers() {
2341 Activate member(s) of the project
2345 $members = $this->getUsers (true) ;
2347 foreach ($members as $member) {
2349 foreach (RBACEngine::getInstance()->getAvailableRolesForUser ($member) as $role) {
2350 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2353 if (!$this->addUser($member->getUnixName(),$role->getID())) {
2360 $res_member = db_query_params ('SELECT user_id,role_id FROM user_group WHERE group_id=$1',
2361 array ($this->getID())) ;
2362 while ($row_member = db_fetch_array($res_member)) {
2363 $u = user_get_object($row_member['user_id']) ;
2364 if (!$this->addUser($u->getUnixName(),$row_member['role_id'])) {
2374 * getMembers - returns array of User objects for this project
2376 * @return array of User objects for this group.
2378 function getMembers() {
2379 return $this->getUsers (true) ;
2383 * replaceTemplateStrings - fill-in some blanks with project name
2385 * @param string Template string
2386 * @return string String after replacements
2388 function replaceTemplateStrings($string) {
2389 $string = str_replace ('UNIXNAME', $this->getUnixName(), $string) ;
2390 $string = str_replace ('PUBLICNAME', $this->getPublicName(), $string) ;
2391 $string = str_replace ('DESCRIPTION', $this->getDescription(), $string) ;
2396 * approve - Approve pending project.
2398 * @param object The User object who is doing the updating.
2401 function approve(&$user) {
2403 require_once $gfcommon.'widget/WidgetLayoutManager.class.php';
2405 if ($this->getStatus()=='A') {
2406 $this->setError(_("Group already active"));
2412 // Step 1: Activate group and create LDAP entries
2413 if (!$this->setStatus($user, 'A')) {
2418 // Switch to system language for item creation
2419 setup_gettext_from_sys_lang ();
2421 // Create default roles
2423 $idadmin_group = NULL ;
2424 foreach (get_group_join_requests ($this) as $gjr) {
2425 $idadmin_group = $gjr->getUserID() ;
2428 if ($idadmin_group == NULL) {
2429 $idadmin_group = $user->getID();
2432 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2433 array ($this->getID(),
2435 if (db_numrows($admin_group) > 0) {
2436 $idadmin_group = db_result($admin_group,0,'user_id');
2438 $idadmin_group = $user->getID();
2439 db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags) VALUES ($1, $2, $3)',
2440 array ($idadmin_group,
2446 $template = $this->getTemplateProject() ;
2447 $id_mappings = array ();
2448 $seen_local_roles = false ;
2450 // Copy roles from template project
2451 foreach ($template->getRoles() as $oldrole) {
2452 if ($oldrole->getHomeProject() != NULL) {
2453 $role = new Role ($this) ;
2455 // Need to use a different role name so that the permissions aren't set from the hardcoded defaults
2456 $role->create ('TEMPORARY ROLE NAME', $data, true) ;
2457 $role->setName ($oldrole->getName()) ;
2458 $seen_local_roles = true ;
2461 $role->linkProject ($this) ;
2463 $id_mappings['role'][$oldrole->getID()] = $role->getID() ;
2464 // Reuse the project_admin permission
2465 $role->setSetting ('project_admin', $this->getID(), $oldrole->getSetting ('project_admin', $template->getID())) ;
2469 if (!$seen_local_roles) {
2470 $role = new Role($this);
2471 $adminperms = array ('project_admin' => array ($this->getID() => 1)) ;
2472 $role_id = $role->create ('Admin', $adminperms, true) ;
2476 $roles = $this->getRoles() ;
2477 foreach ($roles as $r) {
2478 if ($r->getSetting ('project_admin', $this->getID())) {
2479 $r->addUser (user_get_object ($idadmin_group)) ;
2484 // Temporarily switch to the submitter's identity
2485 $saved_session = session_get_user () ;
2486 session_set_internal ($idadmin_group) ;
2489 if (forge_get_config ('use_tracker')) {
2490 $this->setUseTracker ($template->usesTracker()) ;
2491 if ($template->usesTracker()) {
2492 $oldatf = new ArtifactTypeFactory ($template) ;
2493 foreach ($oldatf->getArtifactTypes() as $o) {
2494 $t = new ArtifactType ($this) ;
2495 $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()) ;
2496 $id_mappings['tracker'][$o->getID()] = $t->getID() ;
2497 $t->cloneFieldsFrom ($o->getID()) ;
2502 if (forge_get_config ('use_pm')) {
2503 $this->setUsePM ($template->usesPM()) ;
2504 if ($template->usesPM()) {
2505 $oldpgf = new ProjectGroupFactory ($template) ;
2506 foreach ($oldpgf->getProjectGroups() as $o) {
2507 $pg = new ProjectGroup ($this) ;
2508 $pg->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo()) ;
2509 $id_mappings['pm'][$o->getID()] = $pg->getID() ;
2514 if (forge_get_config ('use_forum')) {
2515 $this->setUseForum ($template->usesForum()) ;
2516 if ($template->usesForum()) {
2517 $oldff = new ForumFactory ($template) ;
2518 foreach ($oldff->getForums() as $o) {
2519 $f = new Forum ($this) ;
2520 $f->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo(),1,$o->allowAnonymous(),$o->getModerationLevel()) ;
2521 $id_mappings['forum'][$o->getID()] = $f->getID() ;
2526 if (forge_get_config ('use_docman')) {
2527 $this->setUseDocman ($template->usesDocman()) ;
2528 if ($template->usesDocman()) {
2529 $olddgf = new DocumentGroupFactory ($template) ;
2530 // First pass: create all docgroups
2531 $id_mappings['docman_docgroup'][0] = 0 ;
2532 foreach ($olddgf->getDocumentGroups() as $o) {
2533 $ndgf = new DocumentGroup ($this) ;
2534 $ndgf->create($this->replaceTemplateStrings($o->getName())) ;
2535 $id_mappings['docman_docgroup'][$o->getID()] = $ndgf->getID() ;
2537 // Second pass: restore hierarchy links
2538 foreach ($olddgf->getDocumentGroups() as $o) {
2539 $ndgf = new DocumentGroup ($this) ;
2540 $ndgf->fetchData ($id_mappings['docman_docgroup'][$o->getID()]) ;
2541 $ndgf->update ($ndgf->getName(),$id_mappings['docman_docgroup'][$o->getParentID()]) ;
2546 if (forge_get_config ('use_frs')) {
2547 $this->setUseFRS ($template->usesFRS()) ;
2548 if ($template->usesFRS()) {
2549 foreach (get_frs_packages ($template) as $o) {
2550 $newp = new FRSPackage ($this) ;
2551 $nname = $this->replaceTemplateStrings($o->getName()) ;
2552 $newp->create ($nname, $o->isPublic()) ;
2557 if (forge_get_config ('use_mail')) {
2558 $this->setUseMail ($template->usesMail()) ;
2559 if ($template->usesMail()) {
2560 $oldmlf = new MailingListFactory ($template) ;
2561 foreach ($oldmlf->getMailingLists() as $o) {
2562 $ml = new MailingList ($this) ;
2563 $nname = preg_replace ('/^'.$template->getUnixName().'-/','',$o->getName()) ;
2565 $ndescription = $this->replaceTemplateStrings($o->getDescription()) ;
2566 $ml->create ($nname, $ndescription, $o->isPublic()) ;
2571 $this->setUseSCM ($template->usesSCM()) ;
2573 foreach ($template->getPlugins() as $plugin_id => $plugin_name) {
2574 $this->setPluginUse ($plugin_name) ;
2577 foreach ($template->getRoles() as $oldrole) {
2578 $newrole = RBACEngine::getInstance()->getRoleById ($id_mappings['role'][$oldrole->getID()]) ;
2579 if ($oldrole->getHomeProject() != NULL
2580 && $oldrole->getHomeProject()->getID() == $template->getID()) {
2581 $newrole->setPublic ($oldrole->isPublic()) ;
2583 $oldsettings = $oldrole->getSettingsForProject ($template) ;
2585 $sections = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm') ;
2586 foreach ($sections as $section) {
2587 $newrole->setSetting ($section, $this->getID(), $oldsettings[$section][$template->getID()]) ;
2590 $sections = array ('tracker', 'pm', 'forum') ;
2591 foreach ($sections as $section) {
2592 if (isset ($oldsettings[$section])) {
2593 foreach ($oldsettings[$section] as $k => $v) {
2594 // Only copy perms for tools that have been copied
2595 if (isset ($id_mappings[$section][$k])) {
2596 $newrole->setSetting ($section,
2597 $id_mappings[$section][$k],
2605 $lm = new WidgetLayoutManager();
2606 $lm->createDefaultLayoutForProject ($this->getID(), $template->getID()) ;
2608 $params = array () ;
2609 $params['template'] = $template ;
2610 $params['project'] = $this ;
2611 $params['id_mappings'] = $id_mappings ;
2612 plugin_hook_by_reference ('clone_project_from_template', $params) ;
2614 // Disable everything
2615 $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, use_ftp=0, use_tracker=0, use_frs=0, use_stats=0 WHERE group_id=$1',
2617 array ($this->getID())) ;
2620 $this->normalizeAllRoles () ;
2621 $this->activateUsers();
2623 // Switch back to user preference
2624 session_set_internal ($saved_session->getID()) ;
2625 setup_gettext_from_context();
2629 $this->sendApprovalEmail();
2630 $this->addHistory('Approved', 'x');
2633 // Plugin can make approve operation there
2636 $params[0] = $idadmin_group ;
2637 $params[1] = $this->getID();
2638 plugin_hook('group_approved',$params);
2646 * sendApprovalEmail - Send new project email.
2648 * @return boolean success.
2651 function sendApprovalEmail() {
2652 $admins = RBACEngine::getInstance()->getUsersByAllowedAction ('project_admin', $this->getID()) ;
2654 if (count($admins) < 1) {
2655 $this->setError(_("Group does not have any administrators."));
2659 // send one email per admin
2660 foreach ($admins as $admin) {
2661 setup_gettext_for_user ($admin) ;
2663 $message=sprintf(_('Your project registration for %4$s has been approved.
2665 Project Full Name: %1$s
2666 Project Unix Name: %2$s
2668 Your DNS will take up to a day to become active on our site.
2669 Your web site is accessible through your shell account. Please read
2670 site documentation (see link below) about intended usage, available
2671 services, and directory layout of the account.
2674 own project page in %4$s while logged in, you will find
2675 additional menu functions to your left labeled \'Project Admin\'.
2677 We highly suggest that you now visit %4$s and create a public
2678 description for your project. This can be done by visiting your project
2679 page while logged in, and selecting \'Project Admin\' from the menus
2680 on the left (or by visiting %3$s
2683 Your project will also not appear in the Trove Software Map (primary
2684 list of projects hosted on %4$s which offers great flexibility in
2685 browsing and search) until you categorize it in the project administration
2686 screens. So that people can find your project, you should do this now.
2687 Visit your project while logged in, and select \'Project Admin\' from the
2690 Enjoy the system, and please tell others about %4$s. Let us know
2691 if there is anything we can do to help you.
2694 htmlspecialchars_decode($this->getPublicName()),
2695 $this->getUnixName(),
2696 util_make_url ('/project/admin/?group_id='.$this->getID()),
2697 forge_get_config ('forge_name'));
2699 util_send_message($admin->getEmail(), sprintf(_('%1$s Project Approved'), forge_get_config ('forge_name')), $message);
2701 setup_gettext_from_context();
2709 * sendRejectionEmail - Send project rejection email.
2711 * This function sends out a rejection message to a user who
2712 * registered a project.
2714 * @param int The id of the response to use.
2715 * @param string The rejection message.
2716 * @return completion status.
2719 function sendRejectionEmail($response_id, $message="zxcv") {
2720 $submitters = array () ;
2722 foreach (get_group_join_requests ($this) as $gjr) {
2723 $submitters[] = user_get_object($gjr->getUserID()) ;
2726 $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",
2728 while ($arr = db_fetch_array ($res)) {
2729 $submitter[] =& user_get_object($arr['user_id']);
2733 if (count ($submitters) < 1) {
2734 $this->setError(_("Group does not have any administrators."));
2738 foreach ($submitters as $admin) {
2739 setup_gettext_for_user ($admin) ;
2741 $response=sprintf(_('Your project registration for %3$s has been denied.
2743 Project Full Name: %1$s
2744 Project Unix Name: %2$s
2746 Reasons for negative decision:
2748 '), $this->getPublicName(), $this->getUnixName(), forge_get_config ('forge_name'));
2750 // Check to see if they want to send a custom rejection response
2751 if ($response_id == 0) {
2752 $response .= $message;
2754 $response .= db_result (
2755 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2760 util_send_message($admin->getEmail(), sprintf(_('%1$s Project Denied'), forge_get_config ('forge_name')), $response);
2761 setup_gettext_from_context();
2768 * sendNewProjectNotificationEmail - Send new project notification email.
2770 * This function sends out a notification email to the
2771 * SourceForge admin user when a new project is
2774 * @return boolean success.
2777 function sendNewProjectNotificationEmail() {
2778 // Get the user who wants to register the project
2779 $submitters = array () ;
2781 foreach (get_group_join_requests ($this) as $gjr) {
2782 $submitters[] = user_get_object($gjr->getUserID()) ;
2785 $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",
2787 while ($arr = db_fetch_array ($res)) {
2788 $submitter[] =& user_get_object($arr['user_id']);
2791 if (count ($submitters) < 1) {
2792 $this->setError(_("Could not find user who has submitted the project."));
2796 $admins = RBACEngine::getInstance()->getUsersByAllowedAction ('approve_projects', -1) ;
2798 if (count($admins) < 1) {
2799 $this->setError(_("There is no administrator to send the mail to."));
2803 foreach ($admins as $admin) {
2804 $admin_email = $admin->getEmail () ;
2805 setup_gettext_for_user ($admin) ;
2807 foreach ($submitters as $u) {
2808 $submitter_names[] = $u->getRealName() ;
2811 $message = sprintf(_('New %1$s Project Submitted
2813 Project Full Name: %2$s
2814 Submitted Description: %3$s
2816 forge_get_config ('forge_name'),
2817 htmlspecialchars_decode($this->getPublicName()),
2818 htmlspecialchars_decode($this->getRegistrationPurpose()));
2820 foreach ($submitters as $submitter) {
2821 $message .= sprintf(_('Submitter: %1$s (%2$s)
2823 $submitter->getRealName(),
2824 $submitter->getUnixName());
2827 $message .= sprintf (_('
2828 Please visit the following URL to approve or reject this project:
2830 util_make_url ('/admin/approve-pending.php')) ;
2831 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2832 setup_gettext_from_context();
2836 $email = $submitter->getEmail() ;
2837 setup_gettext_for_user ($submitter) ;
2839 $message=sprintf(_('New %1$s Project Submitted
2841 Project Full Name: %2$s
2842 Submitted Description: %3$s
2844 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'));
2846 util_send_message($email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2847 setup_gettext_from_context();
2856 * validateGroupName - Validate the group name
2858 * @param string Group name.
2860 * @return an error false and set an error is the group name is invalide otherwise return true
2862 function validateGroupName($group_name) {
2863 if (strlen($group_name)<3) {
2864 $this->setError(_('Group name is too short'));
2866 } else if (strlen(htmlspecialchars($group_name))>50) {
2867 $this->setError(_('Group name is too long'));
2869 } else if ($group=group_get_object_by_publicname($group_name)) {
2870 $this->setError(_('Group name already taken'));
2878 * getRoles - Get the roles of the group.
2880 * @return array of Role id of this group.
2882 function getRolesId () {
2883 $role_ids = array () ;
2886 $res = db_query_params ('SELECT role_id FROM pfo_role WHERE home_group_id=$1',
2887 array ($this->getID()));
2888 while ($arr = db_fetch_array($res)) {
2889 $role_ids[] = $arr['role_id'] ;
2891 $res = db_query_params ('SELECT role_id FROM role_project_refs WHERE group_id=$1',
2892 array ($this->getID()));
2893 while ($arr = db_fetch_array($res)) {
2894 $role_ids[] = $arr['role_id'] ;
2897 $res = db_query_params ('SELECT role_id FROM role WHERE group_id=$1',
2898 array ($this->getID()));
2899 while ($arr = db_fetch_array($res)) {
2900 $role_ids[] = $arr['role_id'] ;
2904 return array_unique ($role_ids) ;
2907 function getRoles () {
2908 $result = array () ;
2910 $roles = $this->getRolesId () ;
2912 $engine = RBACEngine::getInstance() ;
2913 foreach ($roles as $role_id) {
2914 $result[] = $engine->getRoleById ($role_id) ;
2917 foreach ($roles as $role_id) {
2918 $result[] = new Role ($this, $role_id) ;
2925 function normalizeAllRoles () {
2926 $roles = $this->getRoles () ;
2928 foreach ($roles as $r) {
2929 $r->normalizeData () ;
2934 * getUnixStatus - Status of activation of unix account.
2936 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2938 function getUnixStatus() {
2939 return $this->data_array['unix_status'];
2943 * setUnixStatus - Sets status of activation of unix account.
2945 * @param string The unix status.
2951 * @return boolean success.
2953 function setUnixStatus($status) {
2956 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2961 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2965 if ($status == 'A') {
2966 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2967 $this->setError($SYS->getErrorMessage());
2972 if ($SYS->sysCheckGroup($this->getID())) {
2973 if (!$SYS->sysRemoveGroup($this->getID())) {
2974 $this->setError($SYS->getErrorMessage());
2981 $this->data_array['unix_status']=$status;
2988 * getUsers - Get the users of a group
2990 * @return array of user's objects.
2992 function getUsers($onlylocal = true) {
2993 if (!isset($this->membersArr)) {
2994 $this->membersArr = array () ;
2998 foreach ($this->getRoles() as $role) {
3000 && ($role->getHomeProject() == NULL || $role->getHomeProject()->getID() != $this->getID())) {
3003 foreach ($role->getUsers() as $user) {
3004 $ids[] = $user->getID() ;
3007 $ids = array_unique ($ids) ;
3008 foreach ($ids as $id) {
3009 $u = user_get_object ($id) ;
3010 if ($u->isActive()) {
3011 $this->membersArr[] = $u ;
3016 $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',
3017 array ($this->getID(),
3019 if (!$users_group_res) {
3020 $this->setError(_('Error: Enable to get users from group'). ' ' . $this->getID() . ' ' .db_error());
3024 for ($i=0; $i<db_numrows($users_group_res); $i++) {
3025 $this->membersArr[$i] = new GFUser(db_result($users_group_res,$i,'user_id'),false);
3030 return $this->membersArr;
3033 function setDocmanCreateOnlineStatus($status) {
3035 /* if we activate search engine, we probably want to reindex */
3036 $res = db_query_params ('UPDATE groups SET use_docman_create_online=$1 WHERE group_id=$2',
3041 $this->setError(sprintf(_('ERROR - Could Not Update Group DocmanCreateOnline Status: %s'),db_error()));
3045 $this->data_array['use_docman_create_online']=$status;
3051 function setDocmanWebdav($status) {
3053 /* if we activate search engine, we probably want to reindex */
3054 $res = db_query_params ('UPDATE groups SET use_webdav=$1 WHERE group_id=$2',
3059 $this->setError(sprintf(_('ERROR - Could Not Update Group UseWebdab Status: %s'),db_error()));
3063 $this->data_array['use_webdav']=$status;
3069 function setDocmanSearchStatus($status) {
3071 /* if we activate search engine, we probably want to reindex */
3072 $res = db_query_params ('UPDATE groups SET use_docman_search=$1, force_docman_reindex=$1 WHERE group_id=$2',
3077 $this->setError(sprintf(_('ERROR - Could Not Update Group UseDocmanSearch Status: %s'),db_error()));
3081 $this->data_array['use_docman_search']=$status;
3087 function setDocmanForceReindexSearch($status) {
3089 /* if we activate search engine, we probably want to reindex */
3090 $res = db_query_params ('UPDATE groups SET force_docman_reindex=$1 WHERE group_id=$2',
3095 $this->setError(sprintf(_('ERROR - Could Not Update Group force_docman_reindex %s'),db_error()));
3099 $this->data_array['force_docman_reindex']=$status;
3105 function setStorageAPI($type) {
3109 function getStorageAPI() {
3115 * group_getname() - get the group name
3117 * @param int The group ID
3121 function group_getname ($group_id = 0) {
3122 $grp = group_get_object($group_id);
3124 return $grp->getPublicName();
3131 * group_getunixname() - get the unixname for a group
3133 * @param int The group ID
3137 function group_getunixname ($group_id) {
3138 $grp = group_get_object($group_id);
3140 return $grp->getUnixName();
3147 * group_get_result() - Get the group object result ID.
3149 * @param int The group ID
3153 function &group_get_result($group_id=0) {
3154 $grp = group_get_object($group_id);
3156 return $grp->getData();
3162 function getAllProjectTags($onlyvisible = true) {
3163 $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',
3166 if (!$res || db_numrows($res) == 0) {
3172 while ($arr = db_fetch_array($res)) {
3174 $group_id = $arr[1];
3175 if (!isset($result[$tag])) {
3176 $result[$tag] = array();
3179 if (!$onlyvisible || forge_check_perm('project_read', $group_id)) {
3180 $p = group_get_object($group_id);
3181 $result[$tag][] = array('unix_group_name' => $p->getUnixName(),
3182 'group_id' => $group_id);
3189 class ProjectComparator {
3190 var $criterion = 'name' ;
3192 function Compare ($a, $b) {
3193 switch ($this->criterion) {
3196 $namecmp = strcoll ($a->getPublicName(), $b->getPublicName()) ;
3197 if ($namecmp != 0) {
3200 /* If several projects share a same public name */
3201 return strcoll ($a->getUnixName(), $b->getUnixName()) ;
3204 return strcmp ($a->getUnixName(), $b->getUnixName()) ;
3207 $aid = $a->getID() ;
3208 $bid = $b->getID() ;
3212 return ($a < $b) ? -1 : 1;
3218 function sortProjectList (&$list, $criterion='name') {
3219 $cmp = new ProjectComparator () ;
3220 $cmp->criterion = $criterion ;
3222 return usort ($list, array ($cmp, 'Compare')) ;
3227 // c-file-style: "bsd"