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 != ''");
79 function currentProject($val = false)
81 // we do need the option for me to look at all projects...
82 static $currentProject = false;
83 if (empty($_SESSION[__CLASS__])) {
84 $_SESSION[__CLASS__] = array();
87 // attempt to set it..
88 $_SESSION[__CLASS__]['active_project_id'] = $val ;
89 $currentProject = false;
90 // reset to ensure not cached..
92 if ($currentProject !== false) {
93 return $currentProject;
97 $p = DB_DataObject::factory('Projects');
99 if ($this->authUser) {
100 $p->applyFilters(array(), $this->authUser);
101 $p->whereAdd('id in (SELECT distinct(project_id) FROM mtrack_repos)');
102 $ar = $p->fetchAll('id', 'name');
105 if (empty($_SESSION[__CLASS__]['active_project_id']) ||
106 !isset($ar[$_SESSION[__CLASS__]['active_project_id']]))
108 $p = DB_DataObject::factory('Projects');
110 $p->get('code', '*PUBLIC');
112 $_SESSION[__CLASS__]['active_project_id'] = $p->id;
113 $currentProject = $_SESSION[__CLASS__]['active_project_id'];
114 return $p->id; // always allowed..
116 $currentProject = $_SESSION[__CLASS__]['active_project_id'];
117 return $_SESSION[__CLASS__]['active_project_id'];
122 function loadProjectList()
125 $p = DB_DataObject::factory('Projects');
126 if (!$this->authUser) {
127 $p->code = '*PUBLIC';
129 $ar = $p->fetchAll('id', 'name');
132 $p->applyFilters(array(), $this->authUser);
133 $p->whereAdd('id in (SELECT distinct(project_id) FROM mtrack_repos)');
134 $ar = $p->fetchAll('id', 'name');
137 $this->elements['active_project_id'] = new HTML_Template_Flexy_Element();
138 $this->elements['active_project_id']->setOptions($ar);
141 $this->elements['active_project_id']->setValue($this->currentProject());
148 function getAuthUser()
150 $u = DB_DataObject::factory('Person');
154 return $u->getAuthUser();
157 * base getAuth allows everyone in..
162 $this->registerClasses(); // to be destroyed??
164 $ff = HTML_FlexyFramework::get();
169 // default timezone first..
170 $ff = HTML_FlexyFramework::get();
171 if (isset($ff->MTrack['timezone'])) {
172 date_default_timezone_set($ff->MTrack['timezone']);
175 //MTrackConfig::boot(); // eak.. .remove me...
177 $this->authUser = DB_DataObject::factory('Person')->getAuthUser();
178 $this->loadProjectList();
180 if (!$this->authUser) {
181 return true; // we do allow people in this far..
185 // timezone setting... -- this may be a good addon to our core person class.
187 if (!empty($this->authUser->timezone)) {
188 date_default_timezone_set($this->authUser->timezone);
196 return true; // anyone at present..
198 function get($loc='')
202 die ("invalid location". htmlspecialchars($loc));
204 if (!$this->authUser) {
205 return HTML_FlexyFramework::run('Wiki');
207 return HTML_FlexyFramework::run('Wiki/Today');
212 header("Status: 404 Not Found");
217 function initOptions()
221 $q = MTrackDB::q('select priorityname, value from priorities');
223 foreach ($q->fetchAll() as $row) {
224 $this->priorities[$row[0]] = $row[1];
226 $q = MTrackDB::q('select sevname, ordinal from severities');
228 foreach ($q->fetchAll() as $row) {
229 $this->severities[$row[0]] = $row[1];
234 function registerClasses()
236 require_once 'MTrack/Wiki.php';
237 require_once 'MTrack/Wiki/Item.php';
238 require_once 'MTrack/Milestone.php';
241 require_once 'MTrackWeb/LinkHandler.php';
242 require_once 'MTrack/Wiki/HTMLFormatter.php';
244 $this->link = new MTrackWeb_LinkHandler();
245 MTrack_Wiki_HTMLFormatter::registerLinkHandler($this->link);
248 $r = DB_DataObject::factory('mtrack_repos');
249 $r->loadFromPath('default/wiki');
250 MTrack_Wiki_Item::$repo = $r->impl();
254 //MTrack_Wiki::register_macro('MilestoneSummary', array('MTrack_Milestone', 'macro_MilestoneSummary'));
255 // MTrack_Wiki::register_macro('BurnDown', array('MTrack_Milestone', 'macro_BurnDown'));
256 //MTrack_Wiki::register_macro('RunReport', array('MTrack_Report', 'macro_RunReport')); << fixme how are we to hanlde this..
257 //MTrack_Wiki::register_macro('TicketQuery', array('MTrack_Report', 'macro_TicketQuery'));
258 MTrack_Wiki::register_macro('IncludeWikiPage', array('MTrack_Wiki', 'macro_IncludeWiki'));
259 MTrack_Wiki::register_macro('IncludeHelpPage', array('MTrack_Wiki', 'macro_IncludeHelp'));
260 MTrack_Wiki::register_macro('Comment', array('MTrack_Wiki', 'macro_comment'));
261 MTrack_Wiki::register_processor('comment', array('MTrack_Wiki', 'processor_comment'));
262 MTrack_Wiki::register_processor('html', array('MTrack_Wiki', 'processor_html'));
263 MTrack_Wiki::register_processor('dataset', array('MTrack_Wiki', 'processor_dataset'));
266 //MTrackSearchDB::register_indexer('ticket', array('MTrackIssue', 'index_issue'));
267 //MTrackSearchDB::register_indexer('wiki', array('MTrack_Wiki_Item', 'index_item'));
271 //MTrackWatch::registerEventTypes('ticket', array( 'ticket' => 'Tickets' ));
272 //MTrackWatch::registerEventTypes('milestone', array( 'ticket' => 'Tickets', 'changeset' => 'Code changes' ));
273 //MTrackWatch::registerEventTypes('repo', array( 'ticket' => 'Tickets', 'changeset' => 'Code changes' ));
275 // should this get registered here??
276 //MTrackCommitChecker::addCheck('Wiki');
285 /// FIXME - we should allow upload of a favion...
286 $ff = HTML_FlexyFramework::get();
292 /* renders the attachment list for a given object */
293 // was Attachments::render
294 // move it to MTrackWebAttachemnt...
296 function attachmentsToHtml($object)
299 if (is_object($object)) {
300 $object = $object->toIdString(); // eg. ticket:1
302 $atts = MTrackDB::q('
303 select * from attachments
304 left join changes on (attachments.cid = changes.cid)
305 where attachments.object = ? order by changedate, filename',
306 $object)->fetchAll(PDO::FETCH_ASSOC);
308 if (count($atts) == 0) return '';
312 $html = "<div class='attachment-list'><b>Attachments</b><ul>";
313 foreach ($atts as $row) {
314 $url = "{$this->baseURL}/Attachment/$object/". $row['cid'] . '/' . $row['filename'];
316 $html .= "<li><a class='attachment'" .
318 "$row[filename]</a> ($row[size]) added by " .
319 $this->link->username($row['who'], array(
322 " " . $this->link->date($row['changedate']);
323 require_once 'MTrack/Attachment.php';
324 list($width, $height) = getimagesize(MTrackAttachment::local_path($row['hash']));
325 if ($width + $height) {
326 /* limit maximum size */
327 if ($width > $max_dim) {
328 $height *= $max_dim / $width;
331 if ($height > $max_dim) {
332 $width *= $max_dim / $height;
335 $html .= "<br><a href='$url'><img src='$url' width='$width' border='0' height='$height'></a>";
340 $html .= "</ul></div>";
343 function jerr($str, $errors=array()) // standard error reporting..
345 require_once 'Services/JSON.php';
346 $json = new Services_JSON();
349 //$this->addEvent("ERROR", false, $str);
351 if (!empty($_REQUEST['returnHTML']) ||
352 (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']))
354 header('Content-type: text/html');
355 echo "<HTML><HEAD></HEAD><BODY>";
356 echo $json->encodeUnsafe(array(
358 'message' => $str, // compate with exeption / loadexception.
360 'errors' => $errors ? $errors : true, // used by forms to flag errors.
361 'authFailure' => !empty($errors['authFailure']),
363 echo "</BODY></HTML>";
367 echo $json->encode(array(
370 'message' => $str, // compate with exeption / loadexception.
371 'errors' => $errors ? $errors : true, // used by forms to flag errors.
372 'authFailure' => !empty($errors['authFailure']),
380 require_once 'Services/JSON.php';
381 $json = new Services_JSON();
383 if (!empty($_REQUEST['returnHTML']) ||
384 (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']))
387 header('Content-type: text/html');
388 echo "<HTML><HEAD></HEAD><BODY>";
389 echo $json->encodeUnsafe(array('success'=> true, 'data' => $str));
390 echo "</BODY></HTML>";
395 echo $json->encode(array('success'=> true, 'data' => $str));
400 * output data for grids or tree
401 * @ar {Array} ar Array of data
402 * @total {Number|false} total number of records (or false to return count(ar)
403 * @extra {Array} extra key value list of data to pass as extra data.
406 function jdata($ar,$total=false, $extra=array())
408 // should do mobile checking???
409 if ($total == false) {
412 $extra= $extra ? $extra : array();
413 require_once 'Services/JSON.php';
414 $json = new Services_JSON();
415 echo $json->encode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra);
422 * ---------------- Logging ---------------
427 * Log an action (only if it has not been logged already.
429 * @param {String} action - group/name of event
430 * @param {DataObject|false} obj - dataobject action occured on.
431 * @param {String} any remarks
434 function addEventOnce($act, $obj = false, $remarks = '')
436 $au = $this->getAuthUser();
437 $e = DB_DataObject::factory('Events');
438 $e->init($act,$obj,$remarks);
439 if ($e->find(true)) {
442 $this->addEvent($act, $obj, $remarks);
448 * @param {String} action - group/name of event
449 * @param {DataObject|false} obj - dataobject action occured on.
450 * @param {String} any remarks
453 function addEvent($act, $obj = false, $remarks = '')
455 $au = $this->getAuthUser();
456 $e = DB_DataObject::factory('Events');
457 $e->init($act,$obj,$remarks);
459 $e->event_when = date('Y-m-d H:i:s');
462 $ff = HTML_FlexyFramework::get();
463 if (empty($ff->Pman['event_log_dir'])) {
466 $file = $ff->Pman['event_log_dir']. date('/Y/m/d/'). $eid . ".php";
467 if (!file_exists(dirname($file))) {
468 mkdir(dirname($file),0700,true);
470 file_put_contents($file, var_export(array(
471 'REQUEST_URI' => empty($_SERVER['REQUEST_URI']) ? 'cli' : $_SERVER['REQUEST_URI'],
472 'GET' => empty($_GET) ? array() : $_GET,
473 'POST' => empty($_POST) ? array() : $_POST,