3 * every class extends this...
7 class MTrackWeb extends HTML_FlexyFramework_Page
9 var $template = 'wiki.html';
10 var $priorities = array();
11 var $severities = array();
12 var $link = false; // the link handler..
14 function hasPerm($what, $cando) {
15 // our whole perm logic sits in here....
17 // here's how it works
18 // a) anonymous users - not authenticated.
19 // - can see projects that are in *PUBLIC project "MTrack.Repos", "S"
20 // - can see bugs that are in *PUBLIC project "MTrack.Issue", "S"
21 // - can see bugs that are in *PUBLIC project "MTrack.Wiki", "S"
22 if (!$this->authUser) {
24 in_array( $what , array( 'MTrack.Repos', 'MTrack.Issue', 'MTrack.Wiki'))) {
26 return true; // not a diffinative answer...
31 return $this->authUser->hasPerm($what, $cando);
34 function projectPerm($project_id, $what, $cando)
39 $p = DB_DataObject::factory('Projects');
41 if (!$this->authUser) {
42 if ($p->code != '*PUBLIC') {
43 return false; // only public projects
48 // all permissions to view public stuff.
51 if (!$this->authUser->hasPerm($what, $cando)) {
52 echo "NO PERMS $what $cando";
53 echo '<PRE>'; print_r($this->authUser->getPerms());
57 //echo "COMPTYPE " . $this->authUser->company()->comptype ;
58 if ($this->authUser->company()->comptype == 'OWNER') {
60 if ($this->authUser->hasPerm('Core.Projects_All', $cando)) { // they can do what they like on all projects.
63 // return $p->hasPerm($what, $cando);
65 // otherwise they have to be a team member of that project.
67 $pd = DB_DataObject::factory('ProjectDirectory');
68 $pd->project_id = $project_id;
69 $pd->user_id = $this->authUser->id;
70 $pd->whereAdd("role != ''");
80 function currentProject($val = false)
82 // we do need the option for me to look at all projects...
83 static $currentProject = false;
84 if (empty($_SESSION[__CLASS__])) {
85 $_SESSION[__CLASS__] = array();
88 // attempt to set it..
89 $_SESSION[__CLASS__]['active_project_id'] = $val ;
90 $currentProject = false;
91 // reset to ensure not cached..
93 if ($currentProject !== false) {
94 return $currentProject;
98 $p = DB_DataObject::factory('Projects');
100 if ($this->authUser) {
101 $p->applyFilters(array(), $this->authUser);
102 $p->whereAdd('id in (SELECT distinct(project_id) FROM mtrack_repos)');
103 $ar = $p->fetchAll('id', 'name');
108 if (empty($_SESSION[__CLASS__]['active_project_id']) ||
109 !isset($ar[$_SESSION[__CLASS__]['active_project_id']]))
111 $p = DB_DataObject::factory('Projects');
113 $p->get('code', '*PUBLIC');
115 $_SESSION[__CLASS__]['active_project_id'] = $p->id;
116 $currentProject = $_SESSION[__CLASS__]['active_project_id'];
117 return $p->id; // always allowed..
119 $currentProject = $_SESSION[__CLASS__]['active_project_id'];
120 return $_SESSION[__CLASS__]['active_project_id'];
125 function loadProjectList()
128 $p = DB_DataObject::factory('Projects');
129 if (!$this->authUser) {
130 $p->code = '*PUBLIC';
132 $ar = $p->fetchAll('id', 'name');
135 $p->applyFilters(array(), $this->authUser);
136 $p->whereAdd('id in (SELECT distinct(project_id) FROM mtrack_repos)');
137 $ar = $p->fetchAll('id', 'name');
140 $this->elements['active_project_id'] = new HTML_Template_Flexy_Element();
141 $this->elements['active_project_id']->setOptions($ar);
144 $this->elements['active_project_id']->setValue($this->currentProject());
151 function getAuthUser()
153 $u = DB_DataObject::factory('Person');
157 return $u->getAuthUser();
160 * base getAuth allows everyone in..
165 $this->registerClasses(); // to be destroyed??
167 $ff = HTML_FlexyFramework::get();
172 // default timezone first..
173 $ff = HTML_FlexyFramework::get();
174 if (isset($ff->MTrack['timezone'])) {
175 date_default_timezone_set($ff->MTrack['timezone']);
178 //MTrackConfig::boot(); // eak.. .remove me...
180 $this->authUser = DB_DataObject::factory('Person')->getAuthUser();
181 $this->loadProjectList();
183 if (!$this->authUser) {
184 return true; // we do allow people in this far..
188 // timezone setting... -- this may be a good addon to our core person class.
190 if (!empty($this->authUser->timezone)) {
191 date_default_timezone_set($this->authUser->timezone);
199 return true; // anyone at present..
201 function get($loc='')
205 die ("invalid location". htmlspecialchars($loc));
207 if (!$this->authUser) {
208 return HTML_FlexyFramework::run('Wiki');
210 return HTML_FlexyFramework::run('Wiki/Today');
215 header("Status: 404 Not Found");
220 function initOptions()
224 $q = MTrackDB::q('select priorityname, value from priorities');
226 foreach ($q->fetchAll() as $row) {
227 $this->priorities[$row[0]] = $row[1];
229 $q = MTrackDB::q('select sevname, ordinal from severities');
231 foreach ($q->fetchAll() as $row) {
232 $this->severities[$row[0]] = $row[1];
237 function registerClasses()
239 require_once 'MTrack/Wiki.php';
240 require_once 'MTrack/Wiki/Item.php';
241 require_once 'MTrack/Milestone.php';
244 require_once 'MTrackWeb/LinkHandler.php';
245 require_once 'MTrack/Wiki/HTMLFormatter.php';
247 $this->link = new MTrackWeb_LinkHandler();
248 MTrack_Wiki_HTMLFormatter::registerLinkHandler($this->link);
251 $r = DB_DataObject::factory('mtrack_repos');
252 $r->loadFromPath('default/wiki');
253 MTrack_Wiki_Item::$repo = $r->impl();
257 //MTrack_Wiki::register_macro('MilestoneSummary', array('MTrack_Milestone', 'macro_MilestoneSummary'));
258 // MTrack_Wiki::register_macro('BurnDown', array('MTrack_Milestone', 'macro_BurnDown'));
259 //MTrack_Wiki::register_macro('RunReport', array('MTrack_Report', 'macro_RunReport')); << fixme how are we to hanlde this..
260 //MTrack_Wiki::register_macro('TicketQuery', array('MTrack_Report', 'macro_TicketQuery'));
261 MTrack_Wiki::register_macro('IncludeWikiPage', array('MTrack_Wiki', 'macro_IncludeWiki'));
262 MTrack_Wiki::register_macro('IncludeHelpPage', array('MTrack_Wiki', 'macro_IncludeHelp'));
263 MTrack_Wiki::register_macro('Comment', array('MTrack_Wiki', 'macro_comment'));
264 MTrack_Wiki::register_processor('comment', array('MTrack_Wiki', 'processor_comment'));
265 MTrack_Wiki::register_processor('html', array('MTrack_Wiki', 'processor_html'));
266 MTrack_Wiki::register_processor('dataset', array('MTrack_Wiki', 'processor_dataset'));
269 //MTrackSearchDB::register_indexer('ticket', array('MTrackIssue', 'index_issue'));
270 //MTrackSearchDB::register_indexer('wiki', array('MTrack_Wiki_Item', 'index_item'));
274 //MTrackWatch::registerEventTypes('ticket', array( 'ticket' => 'Tickets' ));
275 //MTrackWatch::registerEventTypes('milestone', array( 'ticket' => 'Tickets', 'changeset' => 'Code changes' ));
276 //MTrackWatch::registerEventTypes('repo', array( 'ticket' => 'Tickets', 'changeset' => 'Code changes' ));
278 // should this get registered here??
279 //MTrackCommitChecker::addCheck('Wiki');
288 /// FIXME - we should allow upload of a favion...
289 $ff = HTML_FlexyFramework::get();
295 /* renders the attachment list for a given object */
296 // was Attachments::render
297 // move it to MTrackWebAttachemnt...
299 function attachmentsToHtml($object)
302 if (is_object($object)) {
303 $object = $object->toIdString(); // eg. ticket:1
305 $atts = MTrackDB::q('
306 select * from attachments
307 left join changes on (attachments.cid = changes.cid)
308 where attachments.object = ? order by changedate, filename',
309 $object)->fetchAll(PDO::FETCH_ASSOC);
311 if (count($atts) == 0) return '';
315 $html = "<div class='attachment-list'><b>Attachments</b><ul>";
316 foreach ($atts as $row) {
317 $url = "{$this->baseURL}/Attachment/$object/". $row['cid'] . '/' . $row['filename'];
319 $html .= "<li><a class='attachment'" .
321 "$row[filename]</a> ($row[size]) added by " .
322 $this->link->username($row['who'], array(
325 " " . $this->link->date($row['changedate']);
326 require_once 'MTrack/Attachment.php';
327 list($width, $height) = getimagesize(MTrackAttachment::local_path($row['hash']));
328 if ($width + $height) {
329 /* limit maximum size */
330 if ($width > $max_dim) {
331 $height *= $max_dim / $width;
334 if ($height > $max_dim) {
335 $width *= $max_dim / $height;
338 $html .= "<br><a href='$url'><img src='$url' width='$width' border='0' height='$height'></a>";
343 $html .= "</ul></div>";
346 function jerr($str, $errors=array()) // standard error reporting..
348 require_once 'Services/JSON.php';
349 $json = new Services_JSON();
352 //$this->addEvent("ERROR", false, $str);
354 if (!empty($_REQUEST['returnHTML']) ||
355 (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']))
357 header('Content-type: text/html');
358 echo "<HTML><HEAD></HEAD><BODY>";
359 echo $json->encodeUnsafe(array(
361 'message' => $str, // compate with exeption / loadexception.
363 'errors' => $errors ? $errors : true, // used by forms to flag errors.
364 'authFailure' => !empty($errors['authFailure']),
366 echo "</BODY></HTML>";
370 echo $json->encode(array(
373 'message' => $str, // compate with exeption / loadexception.
374 'errors' => $errors ? $errors : true, // used by forms to flag errors.
375 'authFailure' => !empty($errors['authFailure']),
383 require_once 'Services/JSON.php';
384 $json = new Services_JSON();
386 if (!empty($_REQUEST['returnHTML']) ||
387 (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']))
390 header('Content-type: text/html');
391 echo "<HTML><HEAD></HEAD><BODY>";
392 echo $json->encodeUnsafe(array('success'=> true, 'data' => $str));
393 echo "</BODY></HTML>";
398 echo $json->encode(array('success'=> true, 'data' => $str));
403 * output data for grids or tree
404 * @ar {Array} ar Array of data
405 * @total {Number|false} total number of records (or false to return count(ar)
406 * @extra {Array} extra key value list of data to pass as extra data.
409 function jdata($ar,$total=false, $extra=array())
411 // should do mobile checking???
412 if ($total == false) {
415 $extra= $extra ? $extra : array();
416 require_once 'Services/JSON.php';
417 $json = new Services_JSON();
418 echo $json->encode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra);
425 * ---------------- Logging ---------------
430 * Log an action (only if it has not been logged already.
432 * @param {String} action - group/name of event
433 * @param {DataObject|false} obj - dataobject action occured on.
434 * @param {String} any remarks
437 function addEventOnce($act, $obj = false, $remarks = '')
439 $au = $this->getAuthUser();
440 $e = DB_DataObject::factory('Events');
441 $e->init($act,$obj,$remarks);
442 if ($e->find(true)) {
445 $this->addEvent($act, $obj, $remarks);
451 * @param {String} action - group/name of event
452 * @param {DataObject|false} obj - dataobject action occured on.
453 * @param {String} any remarks
456 function addEvent($act, $obj = false, $remarks = '')
458 $au = $this->getAuthUser();
459 $e = DB_DataObject::factory('Events');
460 $e->init($act,$obj,$remarks);
462 $e->event_when = date('Y-m-d H:i:s');
465 $ff = HTML_FlexyFramework::get();
466 if (empty($ff->Pman['event_log_dir'])) {
469 $file = $ff->Pman['event_log_dir']. date('/Y/m/d/'). $eid . ".php";
470 if (!file_exists(dirname($file))) {
471 mkdir(dirname($file),0700,true);
473 file_put_contents($file, var_export(array(
474 'REQUEST_URI' => empty($_SERVER['REQUEST_URI']) ? 'cli' : $_SERVER['REQUEST_URI'],
475 'GET' => empty($_GET) ? array() : $_GET,
476 'POST' => empty($_POST) ? array() : $_POST,