X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=GroupCountries.php;h=e694d8d8668675773cd932c36d01202837cbae7e;hp=8c4a2e7207135ad1a8cec708c64b8f3943d044c5;hb=c1af5e6bb6064e88469651271f4d9aaff34d69c0;hpb=d2aa2898e75eb1954712ac3ef78884b2afe1a0ec diff --git a/GroupCountries.php b/GroupCountries.php index 8c4a2e72..e694d8d8 100644 --- a/GroupCountries.php +++ b/GroupCountries.php @@ -24,12 +24,12 @@ class Pman_Core_GroupCountries extends Pman return true; } - function get() + function get($v, $opts=array()) { - $this->post(); + $this->post($v); } - function post() + function post($v) { if (!$this->hasPerm( 'Core.Groups','E')) { // editing groups.. $this->jerr("PERMISSION DENIED"); @@ -37,18 +37,46 @@ class Pman_Core_GroupCountries extends Pman $users = explode(',', $_REQUEST['user_ids']); - switch($_REQUEST['action']){ - case 'add': - $this->addPersonToCountry(); - break; - case 'sup': - $this->supPersonToCountry(); - break; - } + $cls = $_REQUEST['action'].'PersonToCountry';// add or sup + $this->$cls($users); print_r($_REQUEST); } + function addPersonToCountry($users) + { + foreach($users as $id){ + $p = DB_DataObject::factory('core_person'); + if(!$p->get($id)){ + $this->jerr('This Person is not exsiting'); + } + $c = explode(',', $p->countries); + $c[] = $_REQUEST['country']; + sort($c); +// print_r($c); + $p->countries = implode(',', $c); + $p->update(); + } + $this->jok(true); + } + function subPersonToCountry($users) + { + foreach($users as $id){ + $p = DB_DataObject::factory('core_person'); + if(!$p->get($id)){ + $this->jerr('This Person is not exsiting'); + } + $c = explode(',', $p->countries); + if(($key = array_search($_REQUEST['country'], $c)) !== false) { + unset($c[$key]); + } + sort($c); +// print_r($c); + $p->countries = implode(',', $c); + $p->update(); + } + $this->jok(true); + } }