1 <?php # vim:ts=2:sw=2:et:
2 /* For licensing and copyright terms, see the file named LICENSE */
8 * b) updateding watchers.
12 require_once 'MTrackWeb.php';
13 class MTrackWeb_Watch extends MTrackWeb
22 var $masterTemplate = 'watch.html';
30 // who is currently watching
31 if (!$this->authUser) {
32 $this->jerr("not authenticated");
33 return ''; // no subscriptin data available to public..
37 $this->objname = empty($_REQUEST['objname']) ? '' : $_REQUEST['objname'];
38 $this->objid = empty($_REQUEST['objid']) ? '' : $_REQUEST['objid'];
40 $this->objname = preg_replace('/[^a-z_]+/i', '', $this->objname );
41 $obj = DB_DataObject::factory($this->objname );
43 // if it's a project watch.. do not do this..
44 if (!$obj->get($this->objid)) {
45 $this->jerr("invalid object");
47 if ($this->objname == 'Projects') {
48 if ($this->objid != $this->currentProject()) {
49 $this->jerr("invalid project id");
52 if ($obj->project_id != $this->currentProject()) {
53 $this->jerr("invalid project id on object");
58 // DB_DataObject::debugLevel(1);
59 $w = DB_DataObjecT::Factory('core_watch');
60 $w->ontable = $this->objname;
61 $w->onid = $this->objid;
64 // $w->orderBy('Person.name ASC');
66 $existing = $w->fetchAll();
68 $this->selfsubscribe = true;
69 foreach($existing as $w) {
70 if ($this->authUser->id == $w->person_id) {
71 $this->selfsubscribe = false;
74 $this->subscribers = $existing;
76 if ($this->objname != 'Projects') {
77 $w = DB_DataObjecT::Factory('core_watch');
78 $w->ontable = 'Projects';
79 $w->onid = $this->currentProject();
81 $existing = $w->fetchAll();
83 $this->selfsubscribe = true;
84 foreach($existing as $w) {
85 if ($this->authUser->id == $w->person_id) {
86 $this->selfsubscribe = false;
89 $this->project_subscribers = $existing;
94 require_once 'HTML/Template/Flexy/Element.php';
95 $this->elements['subscribe-add'] = new HTML_Template_Flexy_Element('select');
96 $this->elements['subscribe-add']->setOptions($users);
97 $this->addsubscribe = true;
98 if (count(array_keys($users)) == 1) {
99 $this->addsubscribe = false;
102 $this->elements['subscribe-add']->setValue('');
105 //$this->renderEvents();
112 if (!$this->authUser) {
113 $this->jerr("not authenticated");
114 return ''; // no subscriptin data available to public..
117 $table = empty($_REQUEST['objname']) ? '' : $_REQUEST['objname'];
118 $id = empty($_REQUEST['objid']) ? '' : $_REQUEST['objid'];
120 if (empty($table) || empty($id)) {
124 if (empty($_REQUEST['userid'])) {
125 die("INVALID USER ID");
128 if ($this->authUser->company()->comptype != 'OWNER') {
129 if ($_REQUEST['userid'] != $this->authUser->id) {
130 die("INVALID REQUEST.");
133 $table = preg_replace('/[^a-z_]+/i', '', $table);
135 // question ... who do we allow to watch what..
136 $o = DB_DataObject::factory($table);
137 if (!is_a($o, 'DB_DataObject')) {
138 die('invalid table');
141 if ($table != 'Projects') {
142 if (empty($o->project_id) || $o->project_id != $this->currentProject()) {
143 die("invalid - project id does not match");
144 // unless it's a project..
147 if ($id != $this->currentProject()) {
148 die("invalid - project id does not match");
154 $w = DB_DataObjecT::Factory('core_watch');
155 $w->ontable = $table;
157 $w->person_id = $_REQUEST['userid'];
158 $w->medium = 'email';
164 // carry on and show get(..