sync
[Pman.Admin] / Signup.php
1 <?php
2
3 require_once 'Pman.php';
4
5 class Pman_Admin_Signup extends Pman 
6 {
7     function getAuth() {
8         parent::getAuth(); // load company!
9         $au = $this->getAuthUser();
10         if (!$au) {
11             $this->jerr("Not authenticated", array('authFailure' => true));
12         }
13         $this->authUser = $au;
14         if ($au->company()->comptype != 'OWNER') {
15              $this->jerr("Permission Denied - not owner company" );
16         }
17         return true;
18     }
19     
20     function post($v)
21     {
22         
23         $si = DB_DataObject::factory('Signup');
24         if (empty($_REQUEST['id']) || ! $si->get($_REQUEST['id'])) {
25             $this->jerr("invalid request");
26         }
27         if ($si->person_id != 0 ){
28             $si->jerr("Account already processed");
29         }
30         // rejected..
31         if ($_REQUEST['person_id'] < 0) {
32             $si->setFrom($_REQUEST);
33             $si->update();
34             $this->jok("OK");
35         }
36         
37         $p = DB_DataObject::factory("core_person");
38         $p->setFrom($_REQUEST);
39         $p->insert();
40         
41         
42         $si->setFrom($_REQUEST);
43         $si->person_id = $p->id;
44         $si->update();
45         
46         // generate a password
47         // and send welcome message.
48         
49         
50         
51         $this->jok($p->toArray());
52     }
53 }