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:') . ' ' .
1612 * getPermission - Return a Permission for this Group
1614 * @return object The Permission.
1616 function &getPermission() {
1617 return permission_get_object($this);
1621 function delete($sure,$really_sure,$really_really_sure) {
1622 if (!$sure || !$really_sure || !$really_really_sure) {
1623 $this->setMissingParamsError(_('Please tick all checkboxes.'));
1626 if ($this->getID() == forge_get_config('news_group') ||
1627 $this->getID() == 1 ||
1628 $this->getID() == forge_get_config('stats_group') ||
1629 $this->getID() == forge_get_config('peer_rating_group')) {
1630 $this->setError(_('Cannot Delete System Group'));
1633 $perm =& $this->getPermission ();
1634 if (!$perm || !is_object($perm)) {
1635 $this->setPermissionDeniedError();
1637 } elseif ($perm->isError()) {
1638 $this->setPermissionDeniedError();
1640 } elseif (!$perm->isSuperUser()) {
1641 $this->setPermissionDeniedError();
1647 // Remove all the members
1649 $members =& $this->getMembers();
1650 foreach ($members as $i) {
1651 $this->removeUser($i->getID());
1653 // Failsafe until user_group table is gone
1654 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1',
1655 array ($this->getID())) ;
1657 // unlink roles from this project
1658 $ra = RoleAnonymous::getInstance();
1659 $rl = RoleLoggedIn::getInstance();
1660 $ra->unlinkProject($this);
1661 $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)) {
1678 $ff = new ForumFactory($this);
1679 $f_arr =& $ff->getForums();
1680 foreach ($f_arr as $i) {
1681 if (!is_object($i)) {
1687 // Delete Subprojects
1689 $pgf = new ProjectGroupFactory($this);
1690 $pg_arr =& $pgf->getProjectGroups();
1691 foreach ($pg_arr as $i) {
1692 if (!is_object($i)) {
1698 // Delete FRS Packages
1700 //$frspf = new FRSPackageFactory($this);
1701 $res = db_query_params ('SELECT * FROM frs_package WHERE group_id=$1',
1702 array ($this->getID())) ;
1703 //echo 'frs_package'.db_error();
1704 //$frsp_arr =& $frspf->getPackages();
1705 while ($arr = db_fetch_array($res)) {
1706 //if (!is_object($pg_arr[$i])) {
1707 // echo "Not Object: ProjectGroup: ".$i;
1710 $frsp=new FRSPackage($this,$arr['package_id'],$arr);
1716 $news_group=group_get_object(forge_get_config('news_group'));
1717 $res = db_query_params ('SELECT forum_id FROM news_bytes WHERE group_id=$1',
1718 array ($this->getID())) ;
1720 $this->setError(_('Error Deleting News: ').db_error());
1725 for ($i=0; $i<db_numrows($res); $i++) {
1726 $Forum = new Forum($news_group,db_result($res,$i,'forum_id'));
1727 if (!$Forum->delete(1,1)) {
1728 printf (_("Could Not Delete News Forum: %d"),$Forum->getID());
1731 $res = db_query_params ('DELETE FROM news_bytes WHERE group_id=$1',
1732 array ($this->getID())) ;
1734 $this->setError(_('Error Deleting News: ').db_error());
1742 $res = db_query_params ('DELETE FROM doc_data WHERE group_id=$1',
1743 array ($this->getID())) ;
1745 $this->setError(_('Error Deleting Documents: ').db_error());
1750 $res = db_query_params ('DELETE FROM doc_groups WHERE group_id=$1',
1751 array ($this->getID())) ;
1753 $this->setError(_('Error Deleting Documents: ').db_error());
1761 $res=db_query_params('DELETE FROM project_tags WHERE group_id=$1', array($this->getID()));
1763 $this->setError(_('Error Deleting Tags: ').db_error());
1769 // Delete group history
1771 $res = db_query_params ('DELETE FROM group_history WHERE group_id=$1',
1772 array ($this->getID())) ;
1774 $this->setError(_('Error Deleting Project History: ').db_error());
1780 // Delete group plugins
1782 $res = db_query_params ('DELETE FROM group_plugin WHERE group_id=$1',
1783 array ($this->getID())) ;
1785 $this->setError(_('Error Deleting Project Plugins: ').db_error());
1791 // Delete group cvs stats
1793 $res = db_query_params ('DELETE FROM stats_cvs_group WHERE group_id=$1',
1794 array ($this->getID())) ;
1796 $this->setError(_('Error Deleting SCM Statistics: ').db_error());
1804 $sf = new SurveyFactory($this);
1805 $s_arr =& $sf->getSurveys();
1806 foreach ($s_arr as $i) {
1807 if (!is_object($i)) {
1810 if (!$i->delete()) {
1811 $this->setError(_('Could not properly delete the survey'));
1817 // Delete SurveyQuestions
1819 $sqf = new SurveyQuestionFactory($this);
1820 $sq_arr =& $sqf->getSurveyQuestions();
1821 foreach ($sq_arr as $i) {
1822 if (!is_object($i)) {
1825 if (!$i->delete()) {
1826 $this->setError(_('Could not properly delete the survey questions'));
1832 // Delete Mailing List Factory
1834 $mlf = new MailingListFactory($this);
1835 $ml_arr = $mlf->getMailingLists();
1836 foreach ($ml_arr as $i) {
1837 if (!is_object($i)) {
1840 if (!$i->delete(1,1)) {
1841 $this->setError(_('Could not properly delete the mailing list'));
1849 $res = db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1',
1850 array ($this->getID())) ;
1852 $this->setError(_('Error Deleting Trove: ').db_error());
1857 $res = db_query_params ('DELETE FROM trove_agg WHERE group_id=$1',
1858 array ($this->getID())) ;
1860 $this->setError(_('Error Deleting Trove: ').db_error());
1868 $res = db_query_params ('DELETE FROM project_sums_agg WHERE group_id=$1',
1869 array ($this->getID())) ;
1871 $this->setError(_('Error Deleting Counters: ').db_error());
1876 $res = db_query_params ('INSERT INTO deleted_groups (unix_group_name,delete_date,isdeleted) VALUES ($1, $2, $3)',
1877 array ($this->getUnixName(),
1881 $this->setError(_('Error Deleting Project:').' '.db_error());
1886 $res = db_query_params ('DELETE FROM groups WHERE group_id=$1',
1887 array ($this->getID())) ;
1889 $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);
1930 Basic functions to add/remove users to/from a group
1931 and update their permissions
1937 * addUser - controls adding a user to a group.
1939 * @param string Unix name of the user to add OR integer user_id.
1940 * @param int The role_id this user should have.
1941 * @return boolean success.
1944 function addUser($user_identifier,$role_id) {
1947 Admins can add users to groups
1950 if (!forge_check_perm ('project_admin', $this->getID())) {
1951 $this->setPermissionDeniedError();
1957 get user id for this user's unix_name
1959 if (is_int ($user_identifier)) { // user_id or user_name
1960 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_id=$1', array ($user_identifier)) ;
1962 $res_newuser = db_query_params ('SELECT * FROM users WHERE user_name=$1', array ($user_identifier)) ;
1964 if (db_numrows($res_newuser) > 0) {
1966 // make sure user is active
1968 if (db_result($res_newuser,0,'status') != 'A') {
1969 $this->setError(_('User is not active. Only active users can be added.'));
1975 // user was found - set new user_id var
1977 $user_id = db_result($res_newuser,0,'user_id');
1979 $role = new Role($this,$role_id);
1980 if (!$role || !is_object($role)) {
1981 $this->setError(_('Error Getting Role Object'));
1984 } elseif ($role->isError()) {
1985 $this->setError('addUser::roleget::'.$role->getErrorMessage());
1991 $role->addUser (user_get_object ($user_id)) ;
1992 if (!$SYS->sysCheckCreateGroup($this->getID())){
1993 $this->setError($SYS->getErrorMessage());
1997 if (!$SYS->sysCheckCreateUser($user_id)) {
1998 $this->setError($SYS->getErrorMessage());
2002 if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
2003 $this->setError($SYS->getErrorMessage());
2010 // if not already a member, add them
2012 $res_member = db_query_params ('SELECT user_id
2014 WHERE user_id=$1 AND group_id=$2',
2015 array ($user_id, $this->getID())) ;
2017 if (db_numrows($res_member) < 1) {
2019 // Create this user's row in the user_group table
2021 $res = db_query_params ('INSERT INTO user_group
2022 (user_id,group_id,admin_flags,forum_flags,project_flags,
2023 doc_flags,cvs_flags,member_role,release_flags,artifact_flags)
2024 VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)',
2036 //verify the insert worked
2037 if (!$res || db_affected_rows($res) < 1) {
2038 $this->setError(sprintf(_('ERROR: Could Not Add User To Group: %s'),db_error()));
2043 // check and create if group doesn't exists
2045 //echo "<h2>Group::addUser SYS->sysCheckCreateGroup(".$this->getID().")</h2>";
2046 if (!$SYS->sysCheckCreateGroup($this->getID())){
2047 $this->setError($SYS->getErrorMessage());
2052 // check and create if user doesn't exists
2054 //echo "<h2>Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
2055 if (!$SYS->sysCheckCreateUser($user_id)) {
2056 $this->setError($SYS->getErrorMessage());
2063 //echo "<h2>Group::addUser role->setUser($user_id)</h2>";
2064 if (!$role->setUser($user_id)) {
2065 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
2071 // user was already a member
2072 // make sure they are set up
2074 $user= user_get_object($user_id,$res_newuser);
2075 $user->fetchData($user->getID());
2076 $role = new Role($this,$role_id);
2077 if (!$role || !is_object($role)) {
2078 $this->setError(_('Error Getting Role Object'));
2081 } elseif ($role->isError()) {
2082 $this->setError('addUser::roleget::'.$role->getErrorMessage());
2086 //echo "<h2>Already Member Group::addUser role->setUser($user_id)</h2>";
2087 if (!$role->setUser($user_id)) {
2088 $this->setError('addUser::role::setUser'.$role->getErrorMessage());
2093 // set up their system info
2095 //echo "<h2>Already Member Group::addUser SYS->sysCheckCreateUser($user_id)</h2>";
2096 if (!$SYS->sysCheckCreateUser($user_id)) {
2097 $this->setError($SYS->getErrorMessage());
2105 // user doesn't exist
2107 $this->setError(_('ERROR: User does not exist'));
2112 $hook_params['group'] = $this;
2113 $hook_params['group_id'] = $this->getID();
2114 $hook_params['user'] = &user_get_object($user_id);
2115 $hook_params['user_id'] = $user_id;
2116 plugin_hook ("group_adduser", $hook_params);
2121 $this->addHistory('Added User',$user_identifier);
2127 * removeUser - controls removing a user from a group.
2129 * Users can remove themselves.
2131 * @param int The ID of the user to remove.
2132 * @return boolean success.
2134 function removeUser($user_id) {
2137 if ($user_id != user_getid()
2138 && !forge_check_perm ('project_admin', $this->getID())) {
2139 $this->setPermissionDeniedError();
2146 $user = user_get_object ($user_id) ;
2147 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
2148 $found_role = NULL ;
2149 foreach ($roles as $role) {
2150 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2151 $found_role = $role ;
2155 if ($found_role == NULL) {
2156 $this->setError(sprintf(_('ERROR: User not removed: %s')));
2160 $found_role->removeUser ($user) ;
2161 if (!$SYS->sysGroupCheckUser($this->getID(),$user_id)) {
2162 $this->setError($SYS->getErrorMessage());
2168 $res = db_query_params ('DELETE FROM user_group WHERE group_id=$1 AND user_id=$2',
2169 array ($this->getID(),
2171 if (!$res || db_affected_rows($res) < 1) {
2172 $this->setError(sprintf(_('ERROR: User not removed: %s'),db_error()));
2179 // reassign open artifacts to id=100
2181 $res = db_query_params ('UPDATE artifact SET assigned_to=100
2182 WHERE group_artifact_id
2183 IN (SELECT group_artifact_id
2184 FROM artifact_group_list
2185 WHERE group_id=$1 AND status_id=1 AND assigned_to=$2)',
2186 array ($this->getID(),
2189 $this->setError(_('ERROR: DB: artifact:').' '.db_error());
2195 // reassign open tasks to id=100
2196 // first have to purge any assignments that would cause
2197 // conflict with existing assignment to 100
2199 $res = db_query_params ('DELETE FROM project_assigned_to
2200 WHERE project_task_id IN (SELECT pt.project_task_id
2201 FROM project_task pt, project_group_list pgl, project_assigned_to pat
2202 WHERE pt.group_project_id = pgl.group_project_id
2203 AND pat.project_task_id=pt.project_task_id
2204 AND pt.status_id=1 AND pgl.group_id=$1
2205 AND pat.assigned_to_id=$2)
2206 AND assigned_to_id=100',
2207 array ($this->getID(),
2210 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),1,db_error()));
2214 $res = db_query_params ('UPDATE project_assigned_to SET assigned_to_id=100
2215 WHERE project_task_id IN (SELECT pt.project_task_id
2216 FROM project_task pt, project_group_list pgl
2217 WHERE pt.group_project_id = pgl.group_project_id
2218 AND pt.status_id=1 AND pgl.group_id=$1)
2219 AND assigned_to_id=$2',
2220 array ($this->getID(),
2223 $this->setError(sprintf(_('ERROR: DB: project_assigned_to %d: %s'),2,db_error()));
2229 // Remove user from system
2231 if (!$SYS->sysGroupRemoveUser($this->getID(),$user_id)) {
2232 $this->setError($SYS->getErrorMessage());
2237 $hook_params['group'] = $this;
2238 $hook_params['group_id'] = $this->getID();
2239 $hook_params['user'] = user_get_object($user_id);
2240 $hook_params['user_id'] = $user_id;
2241 plugin_hook ("group_removeuser", $hook_params);
2244 $this->addHistory('Removed User',$user_id);
2251 * updateUser - controls updating a user's role in this group.
2253 * @param int The ID of the user.
2254 * @param int The role_id to set this user to.
2255 * @return boolean success.
2257 function updateUser($user_id,$role_id) {
2260 if (!forge_check_perm ('project_admin', $this->getID())) {
2261 $this->setPermissionDeniedError();
2266 $newrole = RBACEngine::getInstance()->getRoleById ($role_id) ;
2267 if (!$newrole || !is_object($newrole)) {
2268 $this->setError(_('Could Not Get Role'));
2270 } elseif ($newrole->isError()) {
2271 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2273 } elseif ($newrole->getHomeProject() == NULL
2274 || $newrole->getHomeProject()->getID() != $this->getID()) {
2275 $this->setError(_('Wrong destination role'));
2278 $user = user_get_object ($user_id) ;
2279 $roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
2280 $found_role = NULL ;
2281 foreach ($roles as $role) {
2282 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2283 $found_role = $role ;
2287 if ($found_role == NULL) {
2288 $this->setError(sprintf(_('ERROR: User not removed: %s')));
2292 $found_role->removeUser ($user) ;
2293 $newrole->addUser ($user) ;
2295 $role = new Role($this,$role_id);
2296 if (!$role || !is_object($role)) {
2297 $this->setError(_('Could Not Get Role'));
2299 } elseif ($role->isError()) {
2300 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2303 //echo "<h3>Group::updateUser role->setUser($user_id)</h3>";
2304 if (!$role->setUser($user_id)) {
2305 $this->setError(sprintf(_('Role: %s'),$role->getErrorMessage()));
2310 $this->addHistory('Updated User',$user_id);
2315 * addHistory - Makes an audit trail entry for this project.
2317 * @param string The name of the field.
2318 * @param string The Old Value for this $field_name.
2319 * @return database result handle.
2322 function addHistory($field_name, $old_value) {
2323 return db_query_params ('INSERT INTO group_history(group_id,field_name,old_value,mod_by,adddate)
2324 VALUES ($1,$2,$3,$4,$5)',
2325 array ($this->getID(),
2333 * activateUsers - Make sure that group members have unix accounts.
2335 * Setup unix accounts for group members. Can be called even
2336 * if members are already active.
2340 function activateUsers() {
2342 Activate member(s) of the project
2346 $members = $this->getUsers (true) ;
2348 foreach ($members as $member) {
2350 foreach (RBACEngine::getInstance()->getAvailableRolesForUser ($member) as $role) {
2351 if ($role->getHomeProject() && $role->getHomeProject()->getID() == $this->getID()) {
2354 if (!$this->addUser($member->getUnixName(),$role->getID())) {
2361 $res_member = db_query_params ('SELECT user_id,role_id FROM user_group WHERE group_id=$1',
2362 array ($this->getID())) ;
2363 while ($row_member = db_fetch_array($res_member)) {
2364 $u = user_get_object($row_member['user_id']) ;
2365 if (!$this->addUser($u->getUnixName(),$row_member['role_id'])) {
2375 * getMembers - returns array of User objects for this project
2377 * @return array of User objects for this group.
2379 function getMembers() {
2380 return $this->getUsers (true) ;
2384 * replaceTemplateStrings - fill-in some blanks with project name
2386 * @param string Template string
2387 * @return string String after replacements
2389 function replaceTemplateStrings($string) {
2390 $string = str_replace ('UNIXNAME', $this->getUnixName(), $string) ;
2391 $string = str_replace ('PUBLICNAME', $this->getPublicName(), $string) ;
2392 $string = str_replace ('DESCRIPTION', $this->getDescription(), $string) ;
2397 * approve - Approve pending project.
2399 * @param object The User object who is doing the updating.
2402 function approve(&$user) {
2404 require_once $gfcommon.'widget/WidgetLayoutManager.class.php';
2406 if ($this->getStatus()=='A') {
2407 $this->setError(_("Group already active"));
2413 // Step 1: Activate group and create LDAP entries
2414 if (!$this->setStatus($user, 'A')) {
2419 // Switch to system language for item creation
2420 setup_gettext_from_sys_lang ();
2422 // Create default roles
2424 $idadmin_group = NULL ;
2425 foreach (get_group_join_requests ($this) as $gjr) {
2426 $idadmin_group = $gjr->getUserID() ;
2429 if ($idadmin_group == NULL) {
2430 $idadmin_group = $user->getID();
2433 $admin_group = db_query_params ('SELECT user_id FROM user_group WHERE group_id=$1 AND admin_flags=$2',
2434 array ($this->getID(),
2436 if (db_numrows($admin_group) > 0) {
2437 $idadmin_group = db_result($admin_group,0,'user_id');
2439 $idadmin_group = $user->getID();
2440 db_query_params ('INSERT INTO user_group (user_id, group_id, admin_flags) VALUES ($1, $2, $3)',
2441 array ($idadmin_group,
2447 $template = $this->getTemplateProject() ;
2448 $id_mappings = array ();
2449 $seen_admin_role = false ;
2451 // Copy roles from template project
2452 foreach ($template->getRoles() as $oldrole) {
2453 if ($oldrole->getHomeProject() != NULL) {
2454 $role = new Role ($this) ;
2456 // Need to use a different role name so that the permissions aren't set from the hardcoded defaults
2457 $role->create ('TEMPORARY ROLE NAME', $data, true) ;
2458 $role->setName ($oldrole->getName()) ;
2459 if ($oldrole->getSetting ('project_admin', $template->getID())) {
2460 $seen_admin_role = true ;
2464 $role->linkProject ($this) ;
2466 $id_mappings['role'][$oldrole->getID()] = $role->getID() ;
2467 // Reuse the project_admin permission
2468 $role->setSetting ('project_admin', $this->getID(), $oldrole->getSetting ('project_admin', $template->getID())) ;
2472 if (!$seen_admin_role) {
2473 $role = new Role($this);
2474 $adminperms = array ('project_admin' => array ($this->getID() => 1)) ;
2475 $role_id = $role->create ('Admin', $adminperms, true) ;
2479 $roles = $this->getRoles() ;
2480 foreach ($roles as $r) {
2481 if ($r->getHomeProject() == NULL) {
2484 if ($r->getSetting ('project_admin', $this->getID())) {
2485 $r->addUser (user_get_object ($idadmin_group)) ;
2490 // Temporarily switch to the submitter's identity
2491 $saved_session = session_get_user () ;
2492 session_set_internal ($idadmin_group) ;
2495 if (forge_get_config ('use_tracker')) {
2496 $this->setUseTracker ($template->usesTracker()) ;
2497 if ($template->usesTracker()) {
2498 $oldatf = new ArtifactTypeFactory ($template) ;
2499 foreach ($oldatf->getArtifactTypes() as $o) {
2500 $t = new ArtifactType ($this) ;
2501 $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()) ;
2502 $id_mappings['tracker'][$o->getID()] = $t->getID() ;
2503 $t->cloneFieldsFrom ($o->getID()) ;
2508 if (forge_get_config ('use_pm')) {
2509 $this->setUsePM ($template->usesPM()) ;
2510 if ($template->usesPM()) {
2511 $oldpgf = new ProjectGroupFactory ($template) ;
2512 foreach ($oldpgf->getProjectGroups() as $o) {
2513 $pg = new ProjectGroup ($this) ;
2514 $pg->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo()) ;
2515 $id_mappings['pm'][$o->getID()] = $pg->getID() ;
2520 if (forge_get_config ('use_forum')) {
2521 $this->setUseForum ($template->usesForum()) ;
2522 if ($template->usesForum()) {
2523 $oldff = new ForumFactory ($template) ;
2524 foreach ($oldff->getForums() as $o) {
2525 $f = new Forum ($this) ;
2526 $f->create ($this->replaceTemplateStrings($o->getName()),$this->replaceTemplateStrings($o->getDescription()),$o->isPublic(),$o->getSendAllPostsTo(),1,$o->allowAnonymous(),$o->getModerationLevel()) ;
2527 $id_mappings['forum'][$o->getID()] = $f->getID() ;
2532 if (forge_get_config ('use_docman')) {
2533 $this->setUseDocman ($template->usesDocman()) ;
2534 if ($template->usesDocman()) {
2535 $olddgf = new DocumentGroupFactory ($template) ;
2536 // First pass: create all docgroups
2537 $id_mappings['docman_docgroup'][0] = 0 ;
2538 foreach ($olddgf->getDocumentGroups() as $o) {
2539 $ndgf = new DocumentGroup ($this) ;
2540 $ndgf->create($this->replaceTemplateStrings($o->getName())) ;
2541 $id_mappings['docman_docgroup'][$o->getID()] = $ndgf->getID() ;
2543 // Second pass: restore hierarchy links
2544 foreach ($olddgf->getDocumentGroups() as $o) {
2545 $ndgf = new DocumentGroup ($this) ;
2546 $ndgf->fetchData ($id_mappings['docman_docgroup'][$o->getID()]) ;
2547 $ndgf->update ($ndgf->getName(),$id_mappings['docman_docgroup'][$o->getParentID()]) ;
2552 if (forge_get_config ('use_frs')) {
2553 $this->setUseFRS ($template->usesFRS()) ;
2554 if ($template->usesFRS()) {
2555 foreach (get_frs_packages ($template) as $o) {
2556 $newp = new FRSPackage ($this) ;
2557 $nname = $this->replaceTemplateStrings($o->getName()) ;
2558 $newp->create ($nname, $o->isPublic()) ;
2563 if (forge_get_config ('use_mail')) {
2564 $this->setUseMail ($template->usesMail()) ;
2565 if ($template->usesMail()) {
2566 $oldmlf = new MailingListFactory ($template) ;
2567 foreach ($oldmlf->getMailingLists() as $o) {
2568 $ml = new MailingList ($this) ;
2569 $nname = preg_replace ('/^'.$template->getUnixName().'-/','',$o->getName()) ;
2571 $ndescription = $this->replaceTemplateStrings($o->getDescription()) ;
2572 $ml->create ($nname, $ndescription, $o->isPublic()) ;
2577 $this->setUseSCM ($template->usesSCM()) ;
2579 foreach ($template->getPlugins() as $plugin_id => $plugin_name) {
2580 $this->setPluginUse ($plugin_name) ;
2583 foreach ($template->getRoles() as $oldrole) {
2584 $newrole = RBACEngine::getInstance()->getRoleById ($id_mappings['role'][$oldrole->getID()]) ;
2585 if ($oldrole->getHomeProject() != NULL
2586 && $oldrole->getHomeProject()->getID() == $template->getID()) {
2587 $newrole->setPublic ($oldrole->isPublic()) ;
2589 $oldsettings = $oldrole->getSettingsForProject ($template) ;
2591 $sections = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm') ;
2592 foreach ($sections as $section) {
2593 $newrole->setSetting ($section, $this->getID(), $oldsettings[$section][$template->getID()]) ;
2596 $sections = array ('tracker', 'pm', 'forum') ;
2597 foreach ($sections as $section) {
2598 if (isset ($oldsettings[$section])) {
2599 foreach ($oldsettings[$section] as $k => $v) {
2600 // Only copy perms for tools that have been copied
2601 if (isset ($id_mappings[$section][$k])) {
2602 $newrole->setSetting ($section,
2603 $id_mappings[$section][$k],
2611 $lm = new WidgetLayoutManager();
2612 $lm->createDefaultLayoutForProject ($this->getID(), $template->getID()) ;
2614 $params = array () ;
2615 $params['template'] = $template ;
2616 $params['project'] = $this ;
2617 $params['id_mappings'] = $id_mappings ;
2618 plugin_hook_by_reference ('clone_project_from_template', $params) ;
2620 // Disable everything
2621 $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',
2623 array ($this->getID())) ;
2626 $this->normalizeAllRoles () ;
2627 $this->activateUsers();
2629 // Switch back to user preference
2630 session_set_internal ($saved_session->getID()) ;
2631 setup_gettext_from_context();
2635 $this->sendApprovalEmail();
2636 $this->addHistory('Approved', 'x');
2639 // Plugin can make approve operation there
2642 $params[0] = $idadmin_group ;
2643 $params[1] = $this->getID();
2644 plugin_hook('group_approved',$params);
2652 * sendApprovalEmail - Send new project email.
2654 * @return boolean success.
2657 function sendApprovalEmail() {
2658 $admins = RBACEngine::getInstance()->getUsersByAllowedAction ('project_admin', $this->getID()) ;
2660 if (count($admins) < 1) {
2661 $this->setError(_("Group does not have any administrators."));
2665 // send one email per admin
2666 foreach ($admins as $admin) {
2667 setup_gettext_for_user ($admin) ;
2669 $message=sprintf(_('Your project registration for %4$s has been approved.
2671 Project Full Name: %1$s
2672 Project Unix Name: %2$s
2674 Your DNS will take up to a day to become active on our site.
2675 Your web site is accessible through your shell account. Please read
2676 site documentation (see link below) about intended usage, available
2677 services, and directory layout of the account.
2680 own project page in %4$s while logged in, you will find
2681 additional menu functions to your left labeled \'Project Admin\'.
2683 We highly suggest that you now visit %4$s and create a public
2684 description for your project. This can be done by visiting your project
2685 page while logged in, and selecting \'Project Admin\' from the menus
2686 on the left (or by visiting %3$s
2689 Your project will also not appear in the Trove Software Map (primary
2690 list of projects hosted on %4$s which offers great flexibility in
2691 browsing and search) until you categorize it in the project administration
2692 screens. So that people can find your project, you should do this now.
2693 Visit your project while logged in, and select \'Project Admin\' from the
2696 Enjoy the system, and please tell others about %4$s. Let us know
2697 if there is anything we can do to help you.
2700 htmlspecialchars_decode($this->getPublicName()),
2701 $this->getUnixName(),
2702 util_make_url ('/project/admin/?group_id='.$this->getID()),
2703 forge_get_config ('forge_name'));
2705 util_send_message($admin->getEmail(), sprintf(_('%1$s Project Approved'), forge_get_config ('forge_name')), $message);
2707 setup_gettext_from_context();
2715 * sendRejectionEmail - Send project rejection email.
2717 * This function sends out a rejection message to a user who
2718 * registered a project.
2720 * @param int The id of the response to use.
2721 * @param string The rejection message.
2722 * @return completion status.
2725 function sendRejectionEmail($response_id, $message="zxcv") {
2726 $submitters = array () ;
2728 foreach (get_group_join_requests ($this) as $gjr) {
2729 $submitters[] = user_get_object($gjr->getUserID()) ;
2732 $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",
2734 while ($arr = db_fetch_array ($res)) {
2735 $submitter[] =& user_get_object($arr['user_id']);
2739 if (count ($submitters) < 1) {
2740 $this->setError(_("Group does not have any administrators."));
2744 foreach ($submitters as $admin) {
2745 setup_gettext_for_user ($admin) ;
2747 $response=sprintf(_('Your project registration for %3$s has been denied.
2749 Project Full Name: %1$s
2750 Project Unix Name: %2$s
2752 Reasons for negative decision:
2754 '), $this->getPublicName(), $this->getUnixName(), forge_get_config ('forge_name'));
2756 // Check to see if they want to send a custom rejection response
2757 if ($response_id == 0) {
2758 $response .= $message;
2760 $response .= db_result (
2761 db_query_params('SELECT response_text FROM canned_responses WHERE response_id=$1', array ($response_id)),
2766 util_send_message($admin->getEmail(), sprintf(_('%1$s Project Denied'), forge_get_config ('forge_name')), $response);
2767 setup_gettext_from_context();
2774 * sendNewProjectNotificationEmail - Send new project notification email.
2776 * This function sends out a notification email to the
2777 * SourceForge admin user when a new project is
2780 * @return boolean success.
2783 function sendNewProjectNotificationEmail() {
2784 // Get the user who wants to register the project
2785 $submitters = array () ;
2787 foreach (get_group_join_requests ($this) as $gjr) {
2788 $submitters[] = user_get_object($gjr->getUserID()) ;
2791 $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",
2793 while ($arr = db_fetch_array ($res)) {
2794 $submitter[] =& user_get_object($arr['user_id']);
2797 if (count ($submitters) < 1) {
2798 $this->setError(_("Could not find user who has submitted the project."));
2802 $admins = RBACEngine::getInstance()->getUsersByAllowedAction ('approve_projects', -1) ;
2804 if (count($admins) < 1) {
2805 $this->setError(_("There is no administrator to send the mail to."));
2809 foreach ($admins as $admin) {
2810 $admin_email = $admin->getEmail () ;
2811 setup_gettext_for_user ($admin) ;
2813 foreach ($submitters as $u) {
2814 $submitter_names[] = $u->getRealName() ;
2817 $message = sprintf(_('New %1$s Project Submitted
2819 Project Full Name: %2$s
2820 Submitted Description: %3$s
2822 forge_get_config ('forge_name'),
2823 htmlspecialchars_decode($this->getPublicName()),
2824 htmlspecialchars_decode($this->getRegistrationPurpose()));
2826 foreach ($submitters as $submitter) {
2827 $message .= sprintf(_('Submitter: %1$s (%2$s)
2829 $submitter->getRealName(),
2830 $submitter->getUnixName());
2833 $message .= sprintf (_('
2834 Please visit the following URL to approve or reject this project:
2836 util_make_url ('/admin/approve-pending.php')) ;
2837 util_send_message($admin_email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2838 setup_gettext_from_context();
2842 $email = $submitter->getEmail() ;
2843 setup_gettext_for_user ($submitter) ;
2845 $message=sprintf(_('New %1$s Project Submitted
2847 Project Full Name: %2$s
2848 Submitted Description: %3$s
2850 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'));
2852 util_send_message($email, sprintf(_('New %1$s Project Submitted'), forge_get_config ('forge_name')), $message);
2853 setup_gettext_from_context();
2862 * validateGroupName - Validate the group name
2864 * @param string Group name.
2866 * @return an error false and set an error is the group name is invalide otherwise return true
2868 function validateGroupName($group_name) {
2869 if (strlen($group_name)<3) {
2870 $this->setError(_('Group name is too short'));
2872 } else if (strlen(htmlspecialchars($group_name))>50) {
2873 $this->setError(_('Group name is too long'));
2875 } else if ($group=group_get_object_by_publicname($group_name)) {
2876 $this->setError(_('Group name already taken'));
2884 * getRoles - Get the roles of the group.
2886 * @return array of Role id of this group.
2888 function getRolesId () {
2889 $role_ids = array () ;
2892 $res = db_query_params ('SELECT role_id FROM pfo_role WHERE home_group_id=$1',
2893 array ($this->getID()));
2894 while ($arr = db_fetch_array($res)) {
2895 $role_ids[] = $arr['role_id'] ;
2897 $res = db_query_params ('SELECT role_id FROM role_project_refs WHERE group_id=$1',
2898 array ($this->getID()));
2899 while ($arr = db_fetch_array($res)) {
2900 $role_ids[] = $arr['role_id'] ;
2903 $res = db_query_params ('SELECT role_id FROM role WHERE group_id=$1',
2904 array ($this->getID()));
2905 while ($arr = db_fetch_array($res)) {
2906 $role_ids[] = $arr['role_id'] ;
2910 return array_unique ($role_ids) ;
2913 function getRoles () {
2914 $result = array () ;
2916 $roles = $this->getRolesId () ;
2918 $engine = RBACEngine::getInstance() ;
2919 foreach ($roles as $role_id) {
2920 $result[] = $engine->getRoleById ($role_id) ;
2923 foreach ($roles as $role_id) {
2924 $result[] = new Role ($this, $role_id) ;
2931 function normalizeAllRoles () {
2932 $roles = $this->getRoles () ;
2934 foreach ($roles as $r) {
2935 $r->normalizeData () ;
2940 * getUnixStatus - Status of activation of unix account.
2942 * @return char (N)one, (A)ctive, (S)uspended or (D)eleted
2944 function getUnixStatus() {
2945 return $this->data_array['unix_status'];
2949 * setUnixStatus - Sets status of activation of unix account.
2951 * @param string The unix status.
2957 * @return boolean success.
2959 function setUnixStatus($status) {
2962 $res = db_query_params ('UPDATE groups SET unix_status=$1 WHERE group_id=$2',
2967 $this->setError(sprintf(_('ERROR - Could Not Update Group Unix Status: %s'),db_error()));
2971 if ($status == 'A') {
2972 if (!$SYS->sysCheckCreateGroup($this->getID())) {
2973 $this->setError($SYS->getErrorMessage());
2978 if ($SYS->sysCheckGroup($this->getID())) {
2979 if (!$SYS->sysRemoveGroup($this->getID())) {
2980 $this->setError($SYS->getErrorMessage());
2987 $this->data_array['unix_status']=$status;
2994 * getUsers - Get the users of a group
2996 * @return array of user's objects.
2998 function getUsers($onlylocal = true) {
2999 if (!isset($this->membersArr)) {
3000 $this->membersArr = array () ;
3004 foreach ($this->getRoles() as $role) {
3006 && ($role->getHomeProject() == NULL || $role->getHomeProject()->getID() != $this->getID())) {
3009 foreach ($role->getUsers() as $user) {
3010 $ids[] = $user->getID() ;
3013 $ids = array_unique ($ids) ;
3014 foreach ($ids as $id) {
3015 $u = user_get_object ($id) ;
3016 if ($u->isActive()) {
3017 $this->membersArr[] = $u ;
3022 $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',
3023 array ($this->getID(),
3025 if (!$users_group_res) {
3026 $this->setError(_('Error: Enable to get users from group'). ' ' . $this->getID() . ' ' .db_error());
3030 for ($i=0; $i<db_numrows($users_group_res); $i++) {
3031 $this->membersArr[$i] = new GFUser(db_result($users_group_res,$i,'user_id'),false);
3036 return $this->membersArr;
3039 function setDocmanCreateOnlineStatus($status) {
3041 /* if we activate search engine, we probably want to reindex */
3042 $res = db_query_params ('UPDATE groups SET use_docman_create_online=$1 WHERE group_id=$2',
3047 $this->setError(sprintf(_('ERROR - Could Not Update Group DocmanCreateOnline Status: %s'),db_error()));
3051 $this->data_array['use_docman_create_online']=$status;
3057 function setDocmanWebdav($status) {
3059 /* if we activate search engine, we probably want to reindex */
3060 $res = db_query_params ('UPDATE groups SET use_webdav=$1 WHERE group_id=$2',
3065 $this->setError(sprintf(_('ERROR - Could Not Update Group UseWebdab Status: %s'),db_error()));
3069 $this->data_array['use_webdav']=$status;
3075 function setDocmanSearchStatus($status) {
3077 /* if we activate search engine, we probably want to reindex */
3078 $res = db_query_params ('UPDATE groups SET use_docman_search=$1, force_docman_reindex=$1 WHERE group_id=$2',
3083 $this->setError(sprintf(_('ERROR - Could Not Update Group UseDocmanSearch Status: %s'),db_error()));
3087 $this->data_array['use_docman_search']=$status;
3093 function setDocmanForceReindexSearch($status) {
3095 /* if we activate search engine, we probably want to reindex */
3096 $res = db_query_params ('UPDATE groups SET force_docman_reindex=$1 WHERE group_id=$2',
3101 $this->setError(sprintf(_('ERROR - Could Not Update Group force_docman_reindex %s'),db_error()));
3105 $this->data_array['force_docman_reindex']=$status;
3111 function setStorageAPI($type) {
3115 function getStorageAPI() {
3121 * group_getname() - get the group name
3123 * @param int The group ID
3127 function group_getname ($group_id = 0) {
3128 $grp = group_get_object($group_id);
3130 return $grp->getPublicName();
3137 * group_getunixname() - get the unixname for a group
3139 * @param int The group ID
3143 function group_getunixname ($group_id) {
3144 $grp = group_get_object($group_id);
3146 return $grp->getUnixName();
3153 * group_get_result() - Get the group object result ID.
3155 * @param int The group ID
3159 function &group_get_result($group_id=0) {
3160 $grp = group_get_object($group_id);
3162 return $grp->getData();
3168 function getAllProjectTags($onlyvisible = true) {
3169 $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',
3172 if (!$res || db_numrows($res) == 0) {
3178 while ($arr = db_fetch_array($res)) {
3180 $group_id = $arr[1];
3181 if (!isset($result[$tag])) {
3182 $result[$tag] = array();
3185 if (!$onlyvisible || forge_check_perm('project_read', $group_id)) {
3186 $p = group_get_object($group_id);
3187 $result[$tag][] = array('unix_group_name' => $p->getUnixName(),
3188 'group_id' => $group_id);
3195 class ProjectComparator {
3196 var $criterion = 'name' ;
3198 function Compare ($a, $b) {
3199 switch ($this->criterion) {
3202 $namecmp = strcoll ($a->getPublicName(), $b->getPublicName()) ;
3203 if ($namecmp != 0) {
3206 /* If several projects share a same public name */
3207 return strcoll ($a->getUnixName(), $b->getUnixName()) ;
3210 return strcmp ($a->getUnixName(), $b->getUnixName()) ;
3213 $aid = $a->getID() ;
3214 $bid = $b->getID() ;
3218 return ($a < $b) ? -1 : 1;
3224 function sortProjectList (&$list, $criterion='name') {
3225 $cmp = new ProjectComparator () ;
3226 $cmp->criterion = $criterion ;
3228 return usort ($list, array ($cmp, 'Compare')) ;
3233 // c-file-style: "bsd"