Switch the 'modify' code of admin/field.php to use templates
[bugdar.git] / explain.php
index 8ef882a9cbd95c43deccaabe71efad1b368c8baf..705495b7c99dad754841874513fc9557e2998ed5 100644 (file)
@@ -1,20 +1,30 @@
 <?php
 /*=====================================================================*\
-|| ################################################################### ||
-|| # Bugdar [#]version[#]
-|| # --------------------------------------------------------------- # ||
-|| # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
-|| # This file may not be reproduced in any way without permission.  # ||
-|| # --------------------------------------------------------------- # ||
-|| # User License Agreement at http://www.iris-studios.com/license/  # ||
-|| ################################################################### ||
+|| ###################################################################
+|| # Bugdar
+|| # 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
+|| # the Free Software Foundation; version 2 of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
 \*=====================================================================*/
 
 $fetchtemplates = array(
-       'explain_product'
+       'explain_product',
+       'explain_automation',
+       'explain_row'
 );
 
-define('SVN', '$Id$');
 
 $focus['showreport'] = 'focus';
 
@@ -31,9 +41,14 @@ if (empty($_REQUEST['do']))
 
 if ($_REQUEST['do'] == 'products')
 {
-       foreach ($bugsys->datastore['product'] AS $product)
+       if (!is_array(bugdar::$datastore['product']))
+       {
+               $message->error(T('There are no products set up.'));
+       }
+       
+       foreach (bugdar::$datastore['product'] AS $product)
        {
-               if ($product['componentmother'])
+               if ($product['parentid'])
                {
                        $components["$product[componentmother]"]["$product[productid]"] = $product;
                }
@@ -43,42 +58,137 @@ if ($_REQUEST['do'] == 'products')
                }
        }
        
-       foreach ($bugsys->datastore['version'] AS $version)
+       foreach (bugdar::$datastore['version'] AS $version)
        {
                $versions["$version[productid]"]["$version[versionid]"] = $version;
        }
        
        // global versions
-       foreach ($versions['0'] AS $version)
+       if (is_array($versions['0']))
        {
-               $left = $version['version'];
-               $right = null;
-               eval('$globalversions .= "' . $template->fetch('explain_row') . '";');
+               foreach ($versions['0'] as $version)
+               {
+                       $tpl = new BSTemplate('explain_row');
+                       $tpl->vars = array(
+                               'left'          => $version['version'],
+                       );
+                       $globalversions .= $tpl->evaluate()->getTemplate();
+               }
        }
        
-       foreach ($products AS $product)
+       foreach ($products as $product)
        {
-               $left = $product['title'];
-               $right = $product['description'];
-               $trextra = ' style="background-color: ' . $stylevar['alt_colour'] . '"';
-               eval('$productlist .= "' . $template->fetch('explain_row') . '";');
+               $tpl = new BSTemplate('explain_row');
+               $tpl->vars = array(
+                       'left'          => $product['title'],
+                       'right'         => $product['description'],
+                       'trextra'       => ' class="altcolor"'
+               );
+               $productlist .= $tpl->evaluate()->getTemplate();
                
-               foreach ($components["$product[productid]"] AS $component)
+               if (is_array($components["$product[productid]"]))
+               {
+                       foreach ($components["$product[productid]"] as $component)
+                       {
+                               $tpl = new BSTemplate('explain_row');
+                               $tpl->vars = array(
+                                       'left'          => '&nbsp; &rsaquo; &nbsp; ' . $component['title'],
+                                       'right'         => $component['description'],
+                               );
+                               $productlist .= $tpl->evaluate()->getTemplate();
+                       }
+               }
+       }
+       
+       $tpl = new BSTemplate('explain_product');
+       $tpl->vars = array(
+               'globalversions'        => $globalversions,
+               'productlist'           => $productlist
+       );
+       $tpl->evaluate()->flush();
+}
+
+// ###################################################################
+
+if ($_REQUEST['do'] == 'automations')
+{
+       $fields_fetch = $db->query("
+               SELECT bugfield.*, MAX(permission.mask) AS mask
+               FROM " . TABLE_PREFIX . "bugfield AS bugfield
+               LEFT JOIN " . TABLE_PREFIX . "bugfieldpermission AS permission
+                       ON (bugfield.fieldid = permission.fieldid)
+               WHERE (permission.mask = 2 OR permission.mask = 1)
+               AND permission.usergroupid IN (" . bugdar::$userinfo['usergroupid'] . (sizeof(bugdar::$userinfo['groupids']) != 0 ? ',' . implode(',', bugdar::$userinfo['groupids']) : '') . ")
+               GROUP BY (bugfield.fieldid)
+       ");
+       foreach ($fields_fetch as $field)
+       {
+               $fields["$field[fieldid]"] = $field;
+       }
+       
+       if (is_array(bugdar::$datastore['automation']))
+       {
+               foreach (bugdar::$datastore['automation'] as $automation)
                {
-                       $left = '&nbsp; &rsaquo; &nbsp; ' . $component['title'];
-                       $right = $component['description'];
+                       $automation['fieldchanges'] = unserialize($automation['fieldchanges']);
+                       
+                       $tpl = new BSTemplate('explain_row');
+                       $tpl->vars = array(
+                               'left'          => $automation['name'],
+                               'right'         => $automation['description'],
+                               'trextra'       => ' class="listinghead"'
+                       );
+                       $automations .= $tpl->evaluate()->getTemplate();
+                       
+                       if ($automation['comment'])
+                       {
+                               $tpl = new BSTemplate('explain_row');
+                               $tpl->vars = array(
+                                       'left'          => T('Add Comment'),
+                                       'right'         => $automation['comment'],
+                                       'trextra'       => ' class="altcolor"'
+                               );
+                               $automations .= $tpl->evaluate()->getTemplate();
+                       }
+                       
                        $trextra = '';
-                       eval('$productlist .= "' . $template->fetch('explain_row') . '";');
+                       
+                       if (is_array($automation['fieldchanges']['builtin']))
+                       {
+                               foreach ($automation['fieldchanges']['builtin'] AS $name => $value)
+                               {
+                                       $tpl = new BSTemplate('explain_row');
+                                       $tpl->vars = array(
+                                               'left'          => $name,
+                                               'right'         => bugdar::$datastore["$name"]["$value"]["$name"],
+                                       );
+                                       $automations .= $tpl->evaluate()->getTemplate();
+                               }
+                       }
+                       
+                       if (is_array($automation['fieldchanges']['custom']))
+                       {
+                               foreach ($automation['fieldchanges']['custom'] AS $id => $value)
+                               {
+                                       if (!$fields["$id"])
+                                       {
+                                               continue;
+                                       }
+                                       
+                                       $tpl = new BSTemplate('explain_row');
+                                       $tpl->vars = array(
+                                               'left'          => $fields["$id"]['name'] . ' ' . sprintf(T('(Custom #%1$d, type: %2$s)'), $id, $fields["$id"]['type']),
+                                               'right'         => $value,
+                                       );
+                                       $automations .= $tpl->evaluate()->getTemplate();
+                               }
+                       }
                }
        }
        
-       eval('$template->flush("' . $template->fetch('explain_product') . '");');
+       $tpl = new BSTemplate('explain_automation');
+       $tpl->vars = array('automations' => $automations);
+       $tpl->evaluate()->flush();
 }
 
-/*=====================================================================*\
-|| ###################################################################
-|| # $HeadURL$
-|| # $Id$
-|| ###################################################################
-\*=====================================================================*/
 ?>
\ No newline at end of file