Pman.js
[Pman.Core] / SendIntro.php
1 <?php
2
3 /**
4  * assignment management - for supplier.s
5  * 
6  * call sigs:
7  *   
8  *   _createPasswd : 1  = generate a password
9  *   rawPasswd : use this as a password
10  *    
11  *   _create : 1    (create the account)
12  *      email : email address
13  *      if _createPassword is empty and rawPasswd is empty, then no message is sent.!!!!
14  *   
15  *   _create : 0 // or not set - password sending only.
16  *     id : id of person..
17  *     
18  * 
19  */
20
21 require_once 'Pman.php';
22
23 class Pman_Core_SendIntro extends Pman
24 {
25     
26     function getAuth() 
27     {
28         
29         $au = $this->getAuthUser();
30         if (!$au) {
31             $this->jerr("Not authenticated", array('authFailure' => true));
32         }
33         $this->authUser = $au;
34         // check that it's a supplier!!!! 
35         
36         return true; 
37     }
38     
39     function post($v)
40     {
41         //DB_DataObject::debuglevel(1);
42         //  gets id : c.id,  rawPasswd: c.rawPasswd
43         
44         if (!$this->hasPerm("Core.Person", "A")) {
45              $this->jerr("Not Permitted - no permission to add users.");
46         }
47         $p = DB_DataObject::factory('core_person');
48         
49         // let's make a password anyway..
50         $rawPasswd = false;
51         if (!empty($_REQUEST['_createPasswd'])) {
52             require_once  'Text/Password.php';
53             $rawPasswd = Text_Password::create(6). rand(11,99);
54         }
55         if (!empty($_REQUEST['rawPasswd'])) {
56             $rawPasswd = $_REQUEST['rawPasswd'];
57         }
58         
59         $id = empty($_REQUEST['id']) ? 0 : $_REQUEST['id'];
60         
61         if (!empty($_REQUEST['_create'])) {
62             // check account does not exist yet..
63             if ($p->get('email', $_REQUEST['email'])) {
64                 $this->jerr("duplicate email address:" .$_REQUEST['email']);
65             }
66             $p = DB_DataObject::factory('core_person');
67             $p->setFrom($_REQUEST);
68             
69             if ($rawPasswd == false) {
70                 // -- needed for bulk adding... ?*** not sure why it's here, rather than in Roo?
71                 $p->insert();
72                 $this->jok("OK");
73                 
74             }
75             // generate a password.
76             
77             
78             $p->insert();
79             $id = $p->id;
80             
81         } 
82         
83         
84         $p = DB_DataObject::factory('core_person');
85         
86         if (!$id || !$p->get($_REQUEST['id']))  {
87             $this->jerr("Invalid user id");
88         }
89         
90         
91         if ($rawPasswd !== false) {
92             $p->setPassword($rawPasswd);
93             $p->update();
94         }
95         // next.. 
96         
97         
98         $ret = $p->sendTemplate('password_welcome', array(
99             'sender' => $this->authUser,
100             'rawPasswd' => $rawPasswd,
101             'baseURL' => $this->baseURL,
102         ));
103         if (is_object($ret)) {
104             $this->jerr($ret->toString());
105             
106         }
107         
108         $this->jok("SENT");
109         
110         // 
111        
112          
113     }
114     
115