Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / showreport.php
index 27e2c646343bb068d2565c0c1e50726633cb6f0d..8d0c9ba8d66cf3885a4a4754b1f4ff307f957e07 100644 (file)
@@ -2,7 +2,7 @@
 /*=====================================================================*\
 || ###################################################################
 || # Bugdar
-|| # Copyright ©2002-2007 Blue Static
+|| # Copyright (c)2004-2009 Blue Static
 || #
 || # This program is free software; you can redistribute it and/or modify
 || # it under the terms of the GNU General Public License as published by
@@ -27,7 +27,6 @@ $fetchtemplates = array(
        'bugfield_static_text'
 );
 
-define('SVN', '$Id$');
 
 $focus['showreport'] = 'focus';
 
@@ -42,7 +41,7 @@ if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
 {
        if (!empty($bugid))
        {
-               if ($db->query_first("SELECT bugid FROM " . TABLE_PREFIX . "bug WHERE bugid = $bugid"))
+               if ($db->queryFirst("SELECT bugid FROM " . TABLE_PREFIX . "bug WHERE bugid = $bugid"))
                {
                        header("Location: showreport.php?bugid=$bugid");
                        exit;
@@ -53,7 +52,9 @@ if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
                }
        }
        
-       eval('$template->flush("' . $template->fetch('quicksearch') . '");');
+       $tpl = new BSTemplate('quicksearch');
+       $tpl->vars = array('error' => $error);
+       $tpl->evaluate()->flush();
        exit;
 }
 
@@ -61,7 +62,7 @@ if (empty($bugid) OR $_REQUEST['do'] == 'quicksearch')
 
 // -------------------------------------------------------------------
 // get the report
-$bug = $db->query_first("
+$bug = $db->queryFirst("
        SELECT bug.*, user.email, user.displayname, user.showemail
        FROM " . TABLE_PREFIX . "bug AS bug
        LEFT JOIN " . TABLE_PREFIX . "user AS user
@@ -103,23 +104,26 @@ if ($show['edit'])
                $bug['priority'] = bugdar::$datastore['priority']["$bug[priority]"]['priority'];
        }
        
-       $show['assign'] = (can_perform('canassign', $bug['product']) ? true : false);
-       if (can_perform('canassign', $bug['product']) AND is_array(bugdar::$datastore['assignto']))
+       $show['assign'] = (can_perform('canassign', $bug['product']));
+       if (can_perform('canassign', $bug['product']) && is_array(bugdar::$datastore['assignto']))
        {
-               foreach (bugdar::$datastore['assignto'] AS $dev)
+               foreach (bugdar::$datastore['assignto'] as $dev)
                {
-                       $value = $dev['userid'];
-                       $selected = (($dev['userid'] == $bug['assignedto']) ? true : false);
-                       $label = construct_user_display($dev, false);
-                       eval('$select[dev] .= "' . $template->fetch('selectoption') . '";');
+                       $tpl = new BSTemplate('selectoption');
+                       $tpl->vars = array(
+                               'value'         => $dev['userid'],
+                               'label'         => construct_user_display($dev, false),
+                               'selected'      => ($dev['userid'] == $bug['assignedto'])
+                       );
+                       $select['dev'] .= $tpl->evaluate()->getTemplate();
                }
        }
        
-       $productSelect = ConstructProductSelect('canviewbugs', "$bug[product],$bug[component],$bug[version]");
+       $productSelect = construct_product_select('canviewbugs', "$bug[product],$bug[component],$bug[version]");
        
        if ($bug['duplicateof'])
        {
-               $duplicate = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
+               $duplicate = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
        }
        
        if ($bug['dependency'])
@@ -137,20 +141,26 @@ if ($show['edit'])
        $show['automations'] = false;
        if (is_array(bugdar::$datastore['automation']))
        {
-               foreach (bugdar::$datastore['automation'] AS $action)
+               foreach (bugdar::$datastore['automation'] as $action)
                {
-                       $label = $action['name'];
-                       $value = $action['actionid'];
-                       $selected = false;
-                       eval('$select[automation] .= "' . $template->fetch('selectoption') . '";');
+                       $tpl = new BSTemplate('selectoption');
+                       $tpl->vars = array(
+                               'label'         => $action['name'],
+                               'value'         => $action['actionid'],
+                               'selected'      => false
+                       );
+                       $select['automation'] .= $tpl->evaluate()->getTemplate();
                        $show['automations'] = true;
                }
                if ($show['automations'])
                {
-                       $label = '';
-                       $value = 0;
-                       $selected = true;
-                       eval('$select[automation] = "' . $template->fetch('selectoption') . '" . $select[automation];');
+                       $tpl = new BSTemplate('selectoption');
+                       $tpl->vars = array(
+                               'label'         => '',
+                               'value'         => 0,
+                               'selected'      => true
+                       );
+                       $select['automation'] = $tpl->evaluate()->getTemplate() . $select['automation'];
                }
        }
 }
@@ -169,7 +179,7 @@ else
        $assigninfo = bugdar::$datastore['assignto']["$bug[assignedto]"];
        $bug['assigninfo'] = ((is_array($assigninfo)) ? construct_user_display($assigninfo) : '');
                
-       $duplicateof = $db->query_first("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
+       $duplicateof = $db->queryFirst("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE bugid = $bug[duplicateof]");
        
        $dupelist = array();
        $duplicates = $db->query("SELECT bugid, summary FROM " . TABLE_PREFIX . "bug WHERE duplicateof = $bug[bugid]");
@@ -196,7 +206,7 @@ else
 
 $show['subscribe'] = can_perform('cansubscribe', $bug['product']);
 
-$favorite = (bool)$db->query_first("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE bugid = $bug[bugid] AND userid = " . bugdar::$userinfo['userid']);
+$favorite = (bool)$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "favorite WHERE bugid = $bug[bugid] AND userid = " . bugdar::$userinfo['userid']);
 $favoritetext = ($favorite ? T('Remove from Favorites') : T('Add to Favorites'));
 
 $bug['userinfo'] = construct_user_display($bug);
@@ -231,23 +241,23 @@ foreach ($fields AS $field)
 
 // -------------------------------------------------------------------
 // hilight
-$words = explode(' ', $bugsys->in['hilight']);
+$words = explode(' ', $input->in['hilight']);
 foreach ($words AS $word)
 {
        if (trim($word))
        {
-               $word = preg_quote($bugsys->unsanitize($word));
+               $word = preg_quote($input->unsanitize($word));
                $hilight[] = $temp = trim(preg_replace('#[^0-9a-zA-Z_ ]#', '', $word));
        }
 }
 
 // -------------------------------------------------------------------
 // attachments
-$show['getattachments'] = ((can_perform('cangetattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
-$show['putattachments'] = ((can_perform('canputattach', $bug['productid']) OR can_perform('caneditattach', $bug['productid'])) ? true : false);
-$show['attachments'] = ($show['getattachments'] OR $show['putattachments']) ? true : false;
+$show['getattachments'] = (can_perform('cangetattach', $bug['productid']) || can_perform('caneditattach', $bug['productid']));
+$show['putattachments'] = (can_perform('canputattach', $bug['productid']) || can_perform('caneditattach', $bug['productid']));
+$show['attachments'] = ($show['getattachments'] || $show['putattachments']);
 
-if ($show['getattachments'] OR $show['putattachments'])
+if ($show['getattachments'] || $show['putattachments'])
 {
        $attachments_fetch = $db->query("
                SELECT attachment.attachmentid, attachment.filename,
@@ -265,19 +275,24 @@ if ($show['getattachments'] OR $show['putattachments'])
        foreach ($attachments_fetch as $attachment)
        {
                $attaches = true;
-               $show['editattach'] = ((can_perform('caneditattach', $bug['productid']) OR ($attachment['userid'] == bugdar::$userinfo['userid'] AND can_perform('canputattach', $bug['productid']))) ? true : false);
+               $show['editattach'] = (can_perform('caneditattach', $bug['productid']) || ($attachment['userid'] == bugdar::$userinfo['userid'] && can_perform('canputattach', $bug['productid'])));
                $attachment['date'] = $datef->format(bugdar::$options['dateformat'], $attachment['dateline']);
                $attachment['user'] = construct_user_display($attachment, false);
-               eval('$attachments .= "' . $template->fetch('showreport_attachment') . '";');
+               
+               $tpl = new BSTemplate('showreport_attachment');
+               $tpl->vars = array(
+                       'attachment'    => $attachment
+               );
+               $attachments .= $tpl->evaluate()->getTemplate();
        }
        
-       $show['attachments'] = (!$show['putattachments'] AND !$attaches) ? false : true;
+       $show['attachments'] = ($show['putattachments'] && $attaches);
 }
 
 // -------------------------------------------------------------------
 // votes
 
-$vote = $db->query_first("SELECT *, FIND_IN_SET(" . bugdar::$userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
+$vote = $db->queryFirst("SELECT *, FIND_IN_SET(" . bugdar::$userinfo['userid'] . ", userids) AS uservote FROM " . TABLE_PREFIX . "vote WHERE bugid = $bug[bugid]");
 
 $vote['total'] = $vote['votefor'] + $vote['voteagainst'];
 if ($vote['total'] != 0)
@@ -304,15 +319,16 @@ $comments_fetch = $db->query("
                AND !hidden" : '') . "
        ORDER BY comment.dateline ASC"
 );
+$description = null;
 foreach ($comments_fetch as $comment)
 {
        $comment['posttime'] = $datef->format(bugdar::$options['dateformat'], $comment['dateline']);
        $comment['postby'] = construct_user_display($comment);
        $show['editcomment'] = ((can_perform('caneditownreply', $bug['productid']) AND bugdar::$userinfo['userid'] == $comment['userid']) OR (can_perform('caneditotherreply', $bug['productid']) AND bugdar::$userinfo['userid'] != $comment['userid']));
        
-       $bugsys->debug('can edit own replies: ' . (int)(can_perform('caneditownreply', $bug['productid']) AND bugdar::$userinfo['userid'] == $comment['userid']));
-       $bugsys->debug('can edit other replies:' . (int)(can_perform('caneditotherreply', $bug['productid']) AND bugdar::$userinfo['userid'] != $comment['userid']));
-       $bugsys->debug('$show[editcomment]: ' . $show['editcomment']);
+       BSApp::debug('can edit own replies: ' . (int)(can_perform('caneditownreply', $bug['productid']) AND bugdar::$userinfo['userid'] == $comment['userid']));
+       BSApp::debug('can edit other replies:' . (int)(can_perform('caneditotherreply', $bug['productid']) AND bugdar::$userinfo['userid'] != $comment['userid']));
+       BSApp::debug('$show[editcomment]: ' . $show['editcomment']);
        
        if (is_array($hilight))
        {
@@ -324,7 +340,17 @@ foreach ($comments_fetch as $comment)
                }
        }
        
-       eval('$comments .= "' . $template->fetch('showreport_comment') . '";');
+       $tpl = new BSTemplate('showreport_comment');
+       $tpl->vars = array('comment' => $comment);
+       $temp = $tpl->evaluate()->getTemplate();
+       if ($description == null)
+       {
+               $description = $temp;
+       }
+       else
+       {
+               $comments .= $temp;
+       }
 }
 
 $show['newreply'] = (can_perform('canpostcomments', $bug['productid']) ? true : false);
@@ -340,12 +366,17 @@ if (is_array($hilight) AND !$show['edit'])
        }
 }
 
-eval('$template->flush("' . $template->fetch('showreport') . '");');
+$tpl = new BSTemplate('showreport');
+$tpl->vars = array(
+       'bug'                   => $bug,
+       'comments'              => $comments,
+       'select'                => $select,
+       'vote'                  => $vote,
+       'favoritetext'  => $favoritetext,
+       'customfields'  => $customfields,
+       'attachments'   => $attachments,
+       'productSelect' => $productSelect
+);
+$tpl->evaluate()->flush();
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file