fix #8131 - chinese translations
[Pman.Core] / NotifyAction.php
1 <?php
2 /**
3  * in theory a generic 'action' handler..
4  *
5  * Part of the eventual workflow code...
6  * -> at present, just flags something as done.....
7  *
8  *
9  */
10 require_once 'Pman.php';
11
12 class Pman_Core_NotifyAction extends Pman
13 {
14     
15     function getAuth()
16     {
17         $au = $this->getAuthUser();
18         if (!$au) {
19              $this->jerr("Not authenticated", array('authFailure' => true));
20         }
21         // workflow only applicable to owner company..
22         if ($au->company()->comptype != 'OWNER') {
23             $this->jerr("Core:NotifyAction: invalid user - not owner company.");
24             
25         }
26         
27         $this->authUser = $au;
28         // check that it's a supplier!!!! 
29         
30         return true; 
31     }
32     
33     
34     function get($v, $opts=array())
35     {
36         $this->jerr("invalid request");
37         
38     }
39     function post($v)
40     {
41         // needs: (Array of...)
42         //   on_table,
43         //   action(eg. APPROVAL)
44         //   on_id (comma delimited.)
45         //DB_DataObject::debugLevel(1);
46         $n = DB_DataObject::factory('core_notify');
47         $n->person_id = $this->authUser->id;
48         // in theory in workflow, this could trigger another action...
49         // if watch is on it..
50         foreach(array('ontable','onid','action') as $k) {
51             if (empty($_POST[$k])) {
52                 $this->jerr("missing argument $k");
53             }
54             if ($k == 'onid') {
55                 continue;
56             }
57             $n->$k = $_POST[$k];
58         }
59         
60         $n->whereAdd('sent < act_when'); // not issued yet..
61         $n->whereAdd("join_watch_id_id.medium = '". $n->escape($n->action) ."'");
62         $n->whereAddIn('core_notify.onid', explode(',', $_POST['onid']), 'int' );
63         $n->autoJoin();
64         $ar = $n->fetchAll();
65         
66         $done = array();
67         
68         foreach($ar as $n) {
69             $nc = clone($n);
70             $nc->sent = date('Y-m-d H:i:s');
71             $nc->update($n);
72             
73             // add an event????? - yeap... only once per object
74             $key = implode(':', array($nc->ontable,$nc->onid));
75             if (!isset($done[$key])) { 
76                 
77                 $e = $this->addEvent($_POST['action'],$n->object());
78             }
79             $done[$key] = true;
80         }
81         $this->jok("updated");
82         
83         
84     }
85     
86 }