hide popup message if failure is handled - not sure what knock on effect this may...
[Pman.Core] / GroupCountries.php
1 <?php
2
3 /**
4  * Description of GroupCountries
5  *
6  * @author chris
7  */
8 require_once 'Pman.php';
9
10 class Pman_Core_GroupCountries extends Pman
11 {
12     //put your code here
13     
14     function getAuth() {
15         parent::getAuth(); // load company!
16         $au = $this->getAuthUser();
17         if (!$au) {
18             $this->jerr("Not authenticated", array('authFailure' => true));
19         }
20         if ($au->company()->comptype != 'OWNER') {
21             $this->jerr("Permission Denied" );
22         }
23         $this->authUser = $au;
24         return true;
25     }
26     
27     function get($v, $opts=array())
28     {
29         $this->post($v);
30     }
31     
32     function post($v)
33     {
34         if (!$this->hasPerm( 'Core.Groups','E')) { // editing groups..
35             $this->jerr("PERMISSION DENIED");
36         }
37         
38         $users = explode(',', $_REQUEST['user_ids']);
39         
40         $cls = $_REQUEST['action'].'PersonToCountry';// add or sup
41         $this->$cls($users);
42         
43         print_r($_REQUEST);
44     }
45     
46     function addPersonToCountry($users)
47     {
48         foreach($users as $id){
49             $p = DB_DataObject::factory('core_person');
50             if(!$p->get($id)){
51                 $this->jerr('This Person is not exsiting');
52             }
53             $c = explode(',', $p->countries);
54             $c[] = $_REQUEST['country'];
55             sort($c);
56 //            print_r($c); 
57             $p->countries = implode(',', $c);
58             $p->update();
59         }
60         $this->jok(true);
61     }
62     
63     function subPersonToCountry($users)
64     {
65         foreach($users as $id){
66             $p = DB_DataObject::factory('core_person');
67             if(!$p->get($id)){
68                 $this->jerr('This Person is not exsiting');
69             }
70             $c = explode(',', $p->countries);
71             if(($key = array_search($_REQUEST['country'], $c)) !== false) {
72                 unset($c[$key]);
73             }
74             sort($c); 
75 //            print_r($c);
76             $p->countries = implode(',', $c);
77             $p->update();
78         }
79         $this->jok(true);
80     }
81     
82 }