10 require_once 'Pman.php';
12 class Pman_Core_GroupMembers extends Pman
15 parent::getAuth(); // load company!
16 $au = $this->getAuthUser();
18 $this->jerror("LOGIN-NOAUTH", "Not authenticated", array('authFailure' => true));
20 if ($au->company()->comptype != 'OWNER') {
21 $this->jerr("Permission Denied" );
23 $this->authUser = $au;
28 function get($v, $opts=array())
30 // must recieve a group..
31 if (empty($_GET['group_id']) || (int)$_GET['group_id'] < 1) {
33 $this->jdata(array());
34 //$this->jerr("NO GROUP");
36 if (!$this->hasPerm('Core.Groups', 'S')) {
37 $this->jerr("PERMISSION DENIED");
40 // this is a paging view...
41 // does 2 queries - one for users,
42 // second just flags if they are members..
44 // Groups are only usable by owner company!!!
46 $u = DB_DataObject::factory('core_person');
47 $u->company_id = $this->company->id;
48 //$this->setFilters($u,$_GET);
49 $u->active = 1; // active staff only..
58 $sort = empty($_REQUEST['sort']) ? '' : $_REQUEST['sort'];
59 $dir = (empty($_REQUEST['dir']) || $_REQUEST['dir'] == 'ASC' ? 'ASC' : 'DESC');
61 if (strlen($sort) && isset($cols[$sort])) {
62 $sort = $u->tableName() .'.'.$sort . ' ' . $dir ;
64 } // else other formatas?
69 empty($_REQUEST['start']) ? 0 : (int)$_REQUEST['start'],
70 empty($_REQUEST['limit']) ? 25 : (int)$_REQUEST['limit']
78 'person_id' => $u->id,
85 return $this->jdata($ret,$total);
90 $p = DB_DataObject::factory('core_group_member');
91 $p->group_id = (int)$_GET['group_id'];
92 $p->whereAdd('user_id IN ('. implode(',' ,array_keys($ret) ). ')');
97 $ret[$p->user_id]['id'] = $p->id;
98 $ret[$p->user_id]['isMember'] = 1;
101 $this->jdata(array_values($ret),$total);
108 if (empty($_POST['group_id']) || (int)$_POST['group_id'] < 1) {
109 $this->jerr("NO GROUP");
112 if (!$this->hasPerm( 'Core.Groups','E')) { // editing groups..
113 $this->jerr("PERMISSION DENIED");
117 // NEW DRAG DROP INTERFACE.
118 if (!empty($_POST['action'])) {
120 $ar = explode(',', $_POST['user_ids']);
121 $ac = $_POST['action'];
122 $g = DB_DataObject::factory('core_group');
123 $g->get($_POST['group_id']);
125 foreach($ar as $uid) {
126 $pi = DB_DataObject::factory('core_person');
129 $p = DB_DataObject::factory('core_group_member');
130 $p->group_id = (int)$_POST['group_id'];
134 if (($pi->company()->comptype != 'OWNER') && !$g->type) {
135 $this->jerr("can not add non-owner contact to system group");
139 //$p->type = (int)$_POST['type'];
141 if (($ac == 'sub') && $p->id) {
142 if ($g->leader == $pi->id) {
145 $this->addEvent("DELETE", $p, $g->toEventString(). " Removed " . $pi->toEventString());
149 if (($ac == 'add') && !$p->id) {
152 $this->addEvent("ADD", $p, $g->toEventString(). " Added " . $pi->toEventString());
159 ///---------------- DEPERCIEATED...
161 if (!empty($_POST['dataDelete'])) {
164 foreach($_POST['dataDelete'] as $id => $ac) {
165 $m = DB_DataObject::factory('core_group_member');
172 if (!empty($_POST['dataAdd'])) {
174 foreach($_POST['dataAdd'] as $id => $ac) {
175 $p = DB_DataObject::factory('core_group_member');
176 $p->group_id = (int)$_POST['group_id'];