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;
77 function currentProject()
79 $p = DB_DataObject::factory('Projects');
80 if (!$this->authUser) {
83 $ar = $p->fetchAll('id', 'name');
86 $p->applyFilters(array(), $this->authUser);
87 $p->whereAdd('id in (SELECT distinct(project_id) FROM mtrack_repos)');
88 $ar = $p->fetchAll('id', 'name');
91 if (empty($_SESSION[__CLASS__]['active_project_id']) ||
92 !isset($ar[$_SESSION[__CLASS__]['active_project_id']]))
94 $p = DB_DataObject::factory('Projects');
96 $p->get('code', '*PUBLIC');
97 $_SESSION[__CLASS__]['active_project_id'] = $p->id;
98 return $p->id; // always allowed..
105 function loadProjectList()
108 $p = DB_DataObject::factory('Projects');
109 if (!$this->authUser) {
110 $p->code = '*PUBLIC';
112 $ar = $p->fetchAll('id', 'name');
115 $p->applyFilters(array(), $this->authUser);
116 $p->whereAdd('id in (SELECT distinct(project_id) FROM mtrack_repos)');
117 $ar = $p->fetchAll('id', 'name');
120 $this->elements['active_project_id'] = new HTML_Template_Flexy_Element();
121 $this->elements['active_project_id']->setOptions($ar);
123 if (empty($_SESSION[__CLASS__]['active_project_id']) ||
124 !isset($ar[$_SESSION[__CLASS__]['active_project_id']]))
126 $p = DB_DataObject::factory('Projects');
128 $p->get('code', '*PUBLIC');
129 $_SESSION[__CLASS__]['active_project_id'] = $p->id;
131 $this->elements['active_project_id']->setValue( $_SESSION[__CLASS__]['active_project_id']);
138 function getAuthUser()
140 $u = DB_DataObject::factory('Person');
144 return $u->getAuthUser();
147 * base getAuth allows everyone in..
152 $this->registerClasses(); // to be destroyed??
154 $ff = HTML_FlexyFramework::get();
159 // default timezone first..
160 $ff = HTML_FlexyFramework::get();
161 if (isset($ff->MTrack['timezone'])) {
162 date_default_timezone_set($ff->MTrack['timezone']);
165 //MTrackConfig::boot(); // eak.. .remove me...
167 $this->authUser = DB_DataObject::factory('Person')->getAuthUser();
168 $this->loadProjectList();
170 if (!$this->authUser) {
171 return true; // we do allow people in this far..
175 // timezone setting... -- this may be a good addon to our core person class.
177 if (!empty($this->authUser->timezone)) {
178 date_default_timezone_set($this->authUser->timezone);
186 return true; // anyone at present..
188 function get($loc='')
192 die ("invalid location". htmlspecialchars($loc));
194 if (!$this->authUser) {
195 return HTML_FlexyFramework::run('Wiki');
197 return HTML_FlexyFramework::run('Wiki/Today');
202 header("Status: 404 Not Found");
207 function initOptions()
211 $q = MTrackDB::q('select priorityname, value from priorities');
213 foreach ($q->fetchAll() as $row) {
214 $this->priorities[$row[0]] = $row[1];
216 $q = MTrackDB::q('select sevname, ordinal from severities');
218 foreach ($q->fetchAll() as $row) {
219 $this->severities[$row[0]] = $row[1];
224 function registerClasses()
226 require_once 'MTrack/Wiki.php';
227 require_once 'MTrack/Wiki/Item.php';
228 require_once 'MTrack/Milestone.php';
231 require_once 'MTrackWeb/LinkHandler.php';
232 require_once 'MTrack/Wiki/HTMLFormatter.php';
234 $this->link = new MTrackWeb_LinkHandler();
235 MTrack_Wiki_HTMLFormatter::registerLinkHandler($this->link);
238 $r = DB_DataObject::factory('mtrack_repos');
239 $r->loadFromPath('default/wiki');
240 MTrack_Wiki_Item::$repo = $r->impl();
244 //MTrack_Wiki::register_macro('MilestoneSummary', array('MTrack_Milestone', 'macro_MilestoneSummary'));
245 // MTrack_Wiki::register_macro('BurnDown', array('MTrack_Milestone', 'macro_BurnDown'));
246 //MTrack_Wiki::register_macro('RunReport', array('MTrack_Report', 'macro_RunReport')); << fixme how are we to hanlde this..
247 //MTrack_Wiki::register_macro('TicketQuery', array('MTrack_Report', 'macro_TicketQuery'));
248 MTrack_Wiki::register_macro('IncludeWikiPage', array('MTrack_Wiki', 'macro_IncludeWiki'));
249 MTrack_Wiki::register_macro('IncludeHelpPage', array('MTrack_Wiki', 'macro_IncludeHelp'));
250 MTrack_Wiki::register_macro('Comment', array('MTrack_Wiki', 'macro_comment'));
251 MTrack_Wiki::register_processor('comment', array('MTrack_Wiki', 'processor_comment'));
252 MTrack_Wiki::register_processor('html', array('MTrack_Wiki', 'processor_html'));
253 MTrack_Wiki::register_processor('dataset', array('MTrack_Wiki', 'processor_dataset'));
256 //MTrackSearchDB::register_indexer('ticket', array('MTrackIssue', 'index_issue'));
257 //MTrackSearchDB::register_indexer('wiki', array('MTrack_Wiki_Item', 'index_item'));
261 //MTrackWatch::registerEventTypes('ticket', array( 'ticket' => 'Tickets' ));
262 //MTrackWatch::registerEventTypes('milestone', array( 'ticket' => 'Tickets', 'changeset' => 'Code changes' ));
263 //MTrackWatch::registerEventTypes('repo', array( 'ticket' => 'Tickets', 'changeset' => 'Code changes' ));
265 // should this get registered here??
266 //MTrackCommitChecker::addCheck('Wiki');
275 /// FIXME - we should allow upload of a favion...
276 $ff = HTML_FlexyFramework::get();
282 /* renders the attachment list for a given object */
283 // was Attachments::render
284 // move it to MTrackWebAttachemnt...
286 function attachmentsToHtml($object)
289 if (is_object($object)) {
290 $object = $object->toIdString(); // eg. ticket:1
292 $atts = MTrackDB::q('
293 select * from attachments
294 left join changes on (attachments.cid = changes.cid)
295 where attachments.object = ? order by changedate, filename',
296 $object)->fetchAll(PDO::FETCH_ASSOC);
298 if (count($atts) == 0) return '';
302 $html = "<div class='attachment-list'><b>Attachments</b><ul>";
303 foreach ($atts as $row) {
304 $url = "{$this->baseURL}/Attachment/$object/". $row['cid'] . '/' . $row['filename'];
306 $html .= "<li><a class='attachment'" .
308 "$row[filename]</a> ($row[size]) added by " .
309 $this->link->username($row['who'], array(
312 " " . $this->link->date($row['changedate']);
313 require_once 'MTrack/Attachment.php';
314 list($width, $height) = getimagesize(MTrackAttachment::local_path($row['hash']));
315 if ($width + $height) {
316 /* limit maximum size */
317 if ($width > $max_dim) {
318 $height *= $max_dim / $width;
321 if ($height > $max_dim) {
322 $width *= $max_dim / $height;
325 $html .= "<br><a href='$url'><img src='$url' width='$width' border='0' height='$height'></a>";
330 $html .= "</ul></div>";
333 function jerr($str, $errors=array()) // standard error reporting..
335 require_once 'Services/JSON.php';
336 $json = new Services_JSON();
339 //$this->addEvent("ERROR", false, $str);
341 if (!empty($_REQUEST['returnHTML']) ||
342 (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']))
344 header('Content-type: text/html');
345 echo "<HTML><HEAD></HEAD><BODY>";
346 echo $json->encodeUnsafe(array(
348 'message' => $str, // compate with exeption / loadexception.
350 'errors' => $errors ? $errors : true, // used by forms to flag errors.
351 'authFailure' => !empty($errors['authFailure']),
353 echo "</BODY></HTML>";
357 echo $json->encode(array(
360 'message' => $str, // compate with exeption / loadexception.
361 'errors' => $errors ? $errors : true, // used by forms to flag errors.
362 'authFailure' => !empty($errors['authFailure']),
370 require_once 'Services/JSON.php';
371 $json = new Services_JSON();
373 if (!empty($_REQUEST['returnHTML']) ||
374 (isset($_SERVER['CONTENT_TYPE']) && preg_match('#multipart/form-data#i', $_SERVER['CONTENT_TYPE']))
377 header('Content-type: text/html');
378 echo "<HTML><HEAD></HEAD><BODY>";
379 echo $json->encodeUnsafe(array('success'=> true, 'data' => $str));
380 echo "</BODY></HTML>";
385 echo $json->encode(array('success'=> true, 'data' => $str));
390 * output data for grids or tree
391 * @ar {Array} ar Array of data
392 * @total {Number|false} total number of records (or false to return count(ar)
393 * @extra {Array} extra key value list of data to pass as extra data.
396 function jdata($ar,$total=false, $extra=array())
398 // should do mobile checking???
399 if ($total == false) {
402 $extra= $extra ? $extra : array();
403 require_once 'Services/JSON.php';
404 $json = new Services_JSON();
405 echo $json->encode(array('success' => true, 'total'=> $total, 'data' => $ar) + $extra);
412 * ---------------- Logging ---------------
417 * Log an action (only if it has not been logged already.
419 * @param {String} action - group/name of event
420 * @param {DataObject|false} obj - dataobject action occured on.
421 * @param {String} any remarks
424 function addEventOnce($act, $obj = false, $remarks = '')
426 $au = $this->getAuthUser();
427 $e = DB_DataObject::factory('Events');
428 $e->init($act,$obj,$remarks);
429 if ($e->find(true)) {
432 $this->addEvent($act, $obj, $remarks);
438 * @param {String} action - group/name of event
439 * @param {DataObject|false} obj - dataobject action occured on.
440 * @param {String} any remarks
443 function addEvent($act, $obj = false, $remarks = '')
445 $au = $this->getAuthUser();
446 $e = DB_DataObject::factory('Events');
447 $e->init($act,$obj,$remarks);
449 $e->event_when = date('Y-m-d H:i:s');
452 $ff = HTML_FlexyFramework::get();
453 if (empty($ff->Pman['event_log_dir'])) {
456 $file = $ff->Pman['event_log_dir']. date('/Y/m/d/'). $eid . ".php";
457 if (!file_exists(dirname($file))) {
458 mkdir(dirname($file),0700,true);
460 file_put_contents($file, var_export(array(
461 'REQUEST_URI' => empty($_SERVER['REQUEST_URI']) ? 'cli' : $_SERVER['REQUEST_URI'],
462 'GET' => empty($_GET) ? array() : $_GET,
463 'POST' => empty($_POST) ? array() : $_POST,