Ejemplo n.º 1
0
 function normalizeData()
 {
     // From the PFO spec
     $this->removeObsoleteSettings();
     $this->fetchData($this->getID());
     $projects = $this->getLinkedProjects();
     $new_sa = array();
     $new_pa = array();
     // Add missing settings
     // ...project-wide settings
     if (USE_PFO_RBAC) {
         $arr = array('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm', 'webcal');
         foreach ($projects as $p) {
             foreach ($arr as $section) {
                 $this->normalizePermsForSection($new_pa, $section, $p->getID());
             }
         }
         $this->normalizePermsForSection($new_pa, 'forge_admin', -1);
         $this->normalizePermsForSection($new_pa, 'approve_projects', -1);
         $this->normalizePermsForSection($new_pa, 'approve_news', -1);
         $this->normalizePermsForSection($new_pa, 'forge_stats', -1);
     } else {
         $arr = array('projectadmin', 'frs', 'scm', 'docman', 'forumadmin', 'trackeradmin', 'newtracker', 'pmadmin', 'newpm', 'webcal');
         foreach ($arr as $section) {
             $this->normalizeDataForSection($new_sa, $section);
         }
     }
     $hook_params = array();
     $hook_params['role'] =& $this;
     $hook_params['new_sa'] =& $new_sa;
     $hook_params['new_pa'] =& $new_pa;
     plugin_hook("role_normalize", $hook_params);
     // ...tracker-related settings
     $new_sa['tracker'] = array();
     $new_pa['tracker'] = array();
     foreach ($projects as $p) {
         $atf = new ArtifactTypeFactory($p);
         $trackerids = $atf->getAllArtifactTypeIds();
         foreach ($trackerids as $tid) {
             if (USE_PFO_RBAC) {
                 if (array_key_exists('tracker', $this->perms_array) && array_key_exists($tid, $this->perms_array['tracker'])) {
                     $new_pa['tracker'][$tid] = $this->perms_array['tracker'][$tid];
                 } elseif (array_key_exists('new_tracker', $this->perms_array) && array_key_exists($p->getID(), $this->perms_array['new_tracker'])) {
                     $new_pa['tracker'][$tid] = $new_pa['new_tracker'][$p->getID()];
                 }
             } else {
                 if (array_key_exists('tracker', $this->setting_array) && array_key_exists($tid, $this->setting_array['tracker'])) {
                     $new_sa['tracker'][$tid] = $this->setting_array['tracker'][$tid];
                 } else {
                     $new_sa['tracker'][$tid] = $new_sa['newtracker'][0];
                 }
             }
         }
     }
     // ...forum-related settings
     $new_sa['forum'] = array();
     $new_pa['forum'] = array();
     foreach ($projects as $p) {
         $ff = new ForumFactory($p);
         $fids = $ff->getAllForumIds();
         foreach ($fids as $fid) {
             if (USE_PFO_RBAC) {
                 if (array_key_exists('forum', $this->perms_array) && array_key_exists($fid, $this->perms_array['forum'])) {
                     $new_pa['forum'][$fid] = $this->perms_array['forum'][$fid];
                 } elseif (array_key_exists('new_forum', $this->perms_array) && array_key_exists($p->getID(), $this->perms_array['new_forum'])) {
                     $new_pa['forum'][$fid] = $new_pa['new_forum'][$p->getID()];
                 }
             } else {
                 if (array_key_exists('forum', $this->setting_array) && array_key_exists($fid, $this->setting_array['forum'])) {
                     $new_sa['forum'][$fid] = $this->setting_array['forum'][$fid];
                 } else {
                     $new_sa['forum'][$fid] = $new_sa['newforum'][0];
                 }
             }
         }
     }
     // ...pm-related settings
     $new_sa['pm'] = array();
     $new_pa['pm'] = array();
     foreach ($projects as $p) {
         $pgf = new ProjectGroupFactory($p);
         $pgids = $pgf->getAllProjectGroupIds();
         foreach ($pgids as $gid) {
             if (USE_PFO_RBAC) {
                 if (array_key_exists('pm', $this->perms_array) && array_key_exists($gid, $this->perms_array['pm'])) {
                     $new_pa['pm'][$gid] = $this->perms_array['pm'][$gid];
                 } elseif (array_key_exists('new_pm', $this->perms_array) && array_key_exists($p->getID(), $this->perms_array['new_pm'])) {
                     $new_pa['pm'][$gid] = $new_pa['new_pm'][$p->getID()];
                 }
             } else {
                 if (array_key_exists('pm', $this->setting_array) && array_key_exists($gid, $this->setting_array['pm'])) {
                     $new_sa['pm'][$gid] = $this->setting_array['pm'][$gid];
                 } else {
                     $new_sa['pm'][$gid] = $new_sa['newpm'][0];
                 }
             }
         }
     }
     // Save
     if (USE_PFO_RBAC) {
         $this->update($this->getName(), $new_pa, false);
     } else {
         $this->update($this->getName(), $new_sa);
     }
     return true;
 }
Ejemplo n.º 2
0
 function delete($sure, $really_sure, $really_really_sure)
 {
     if (!$sure || !$really_sure || !$really_really_sure) {
         $this->setMissingParamsError();
         return false;
     }
     if ($this->getID() == $GLOBALS['sys_news_group'] || $this->getID() == 1 || $this->getID() == $GLOBALS['sys_stats_group'] || $this->getID() == $GLOBALS['sys_peer_rating_group']) {
         $this->setError(_('Cannot Delete System Group'));
         return false;
     }
     $perm =& $this->getPermission(session_get_user());
     if (!$perm || !is_object($perm)) {
         $this->setPermissionDeniedError();
         return false;
     } elseif ($perm->isError()) {
         $this->setPermissionDeniedError();
         return false;
     } elseif (!$perm->isSuperUser()) {
         $this->setPermissionDeniedError();
         return false;
     }
     db_begin();
     //
     //	Remove all the members
     //
     $members =& $this->getMembers();
     for ($i = 0; $i < count($members); $i++) {
         $this->removeUser($members[$i]->getID());
     }
     //
     //	Delete Trackers
     //
     $atf = new ArtifactTypeFactory($this);
     $at_arr =& $atf->getArtifactTypes();
     for ($i = 0; $i < count($at_arr); $i++) {
         if (!is_object($at_arr[$i])) {
             printf(_("Not Object: ArtifactType: %d"), $i);
             continue;
         }
         $at_arr[$i]->delete(1, 1);
     }
     //
     //	Delete Forums
     //
     $ff = new ForumFactory($this);
     $f_arr =& $ff->getForums();
     for ($i = 0; $i < count($f_arr); $i++) {
         if (!is_object($f_arr[$i])) {
             printf(_("Not Object: Forum: %d"), $i);
             continue;
         }
         $f_arr[$i]->delete(1, 1);
         //echo 'ForumFactory'.db_error();
     }
     //
     //	Delete Subprojects
     //
     $pgf = new ProjectGroupFactory($this);
     $pg_arr =& $pgf->getProjectGroups();
     for ($i = 0; $i < count($pg_arr); $i++) {
         if (!is_object($pg_arr[$i])) {
             printf(_("Not Object: ProjectGroup: %d"), $i);
             continue;
         }
         $pg_arr[$i]->delete(1, 1);
         //echo 'ProjectGroupFactory'.db_error();
     }
     //
     //	Delete FRS Packages
     //
     //$frspf = new FRSPackageFactory($this);
     $res = db_query("SELECT * FROM frs_package WHERE group_id='" . $this->getID() . "'");
     //echo 'frs_package'.db_error();
     //$frsp_arr =& $frspf->getPackages();
     while ($arr = db_fetch_array($res)) {
         //if (!is_object($pg_arr[$i])) {
         //	echo "Not Object: ProjectGroup: ".$i;
         //	continue;
         //}
         $frsp = new FRSPackage($this, $arr['package_id'], $arr);
         $frsp->delete(1, 1);
     }
     //
     //	Delete news
     //
     $news_group =& group_get_object($GLOBALS['sys_news_group']);
     $res = db_query("SELECT forum_id FROM news_bytes WHERE group_id='" . $this->getID() . "'");
     for ($i = 0; $i < db_numrows($res); $i++) {
         $Forum = new Forum($news_group, db_result($res, $i, 'forum_id'));
         if (!$Forum->delete(1, 1)) {
             printf(_("Could Not Delete News Forum: %d"), $Forum->getID());
         }
     }
     $res = db_query("DELETE FROM news_bytes WHERE group_id='" . $this->getID() . "'");
     //
     //	Delete docs
     //
     $res = db_query("DELETE FROM doc_data WHERE group_id='" . $this->getID() . "'");
     //echo 'doc_data'.db_error();
     $res = db_query("DELETE FROM doc_groups WHERE group_id='" . $this->getID() . "'");
     //echo 'doc_groups'.db_error();
     //
     //	Delete group history
     //
     $res = db_query("DELETE FROM group_history WHERE group_id='" . $this->getID() . "'");
     //echo 'group_history'.db_error();
     //
     //	Delete group plugins
     //
     $res = db_query("DELETE FROM group_plugin WHERE group_id='" . $this->getID() . "'");
     //echo 'group_plugin'.db_error();
     //
     //	Delete group cvs stats
     //
     $res = db_query("DELETE FROM stats_cvs_group WHERE group_id='" . $this->getID() . "'");
     //echo 'stats_cvs_group'.db_error();
     //
     //	Delete Surveys
     //
     $sf = new SurveyFactory($this);
     $s_arr =& $sf->getSurveys();
     for ($i = 0; $i < count($s_arr); $i++) {
         if (!is_object($s_arr[$i])) {
             printf(_("Not Object: Survey: %d"), $i);
             continue;
         }
         $s_arr[$i]->delete();
         //echo 'SurveyFactory'.db_error();
     }
     //
     //	Delete SurveyQuestions
     //
     $sqf = new SurveyQuestionFactory($this);
     $sq_arr =& $sqf->getSurveyQuestions();
     for ($i = 0; $i < count($sq_arr); $i++) {
         if (!is_object($sq_arr[$i])) {
             printf(_("Not Object: SurveyQuestion: %d"), $i);
             continue;
         }
         $sq_arr[$i]->delete();
         //echo 'SurveyQuestionFactory'.db_error();
     }
     //
     //	Delete Mailing List Factory
     //
     $mlf = new MailingListFactory($this);
     $ml_arr =& $mlf->getMailingLists();
     for ($i = 0; $i < count($ml_arr); $i++) {
         if (!is_object($ml_arr[$i])) {
             printf(_("Not Object: MailingList: %d"), $i);
             continue;
         }
         if (!$ml_arr[$i]->delete(1, 1)) {
             $this->setError(_('Could not properly delete the mailing list'));
         }
         //echo 'MailingListFactory'.db_error();
     }
     //
     //	Delete trove
     //
     $res = db_query("DELETE FROM trove_group_link WHERE group_id='" . $this->getID() . "'");
     $res = db_query("DELETE FROM trove_agg WHERE group_id='" . $this->getID() . "'");
     //
     //	Delete counters
     //
     $res = db_query("DELETE FROM project_sums_agg WHERE group_id='" . $this->getID() . "'");
     //echo 'project_sums_agg'.db_error();
     $res = db_query("INSERT INTO deleted_groups (\n\t\tunix_group_name,delete_date,isdeleted) VALUES \n\t\t('" . $this->getUnixName() . "','" . time() . "','0')");
     //echo 'InsertIntoDeleteQueue'.db_error();
     $res = db_query("DELETE FROM groups WHERE group_id='" . $this->getID() . "'");
     //echo 'DeleteGroup'.db_error();
     db_commit();
     if (!$res) {
         return false;
     }
     $hook_params = array();
     $hook_params['group'] = $this;
     $hook_params['group_id'] = $this->getID();
     plugin_hook("group_delete", $hook_params);
     if (isset($GLOBALS['sys_upload_dir']) && $this->getUnixName()) {
         exec('/bin/rm -rf ' . $GLOBALS['sys_upload_dir'] . '/' . $this->getUnixName() . '/');
     }
     if (isset($GLOBALS['sys_ftp_upload_dir']) && $this->getUnixName()) {
         exec('/bin/rm -rf ' . $GLOBALS['sys_ftp_upload_dir'] . '/' . $this->getUnixName() . '/');
     }
     //
     //	Delete reporting
     //
     $res = db_query("DELETE FROM rep_group_act_weekly WHERE group_id='" . $this->getID() . "'");
     //echo 'rep_group_act_weekly'.db_error();
     $res = db_query("DELETE FROM rep_group_act_monthly WHERE group_id='" . $this->getID() . "'");
     //echo 'rep_group_act_monthly'.db_error();
     $res = db_query("DELETE FROM rep_group_act_daily WHERE group_id='" . $this->getID() . "'");
     //echo 'rep_group_act_daily'.db_error();
     unset($this->data_array);
     return true;
 }