Main Page | Directories | File List | File Members

include/trackers_run/admin/editqueryforms.php

Go to the documentation of this file.
00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: editqueryforms.php 5441 2006-02-19 13:53:40Z toddy $
00006 #
00007 #  Copyright 2001-2002 (c) Laurent Julliard, CodeX Team, Xerox
00008 #
00009 #  Copyright 2003-2004 (c) Mathieu Roy <yeupou--at--gnu.org>
00010 #
00011 # The Savane project is free software; you can redistribute it and/or
00012 # modify it under the terms of the GNU General Public License
00013 # as published by the Free Software Foundation; either version 2
00014 # of the License, or (at your option) any later version.
00015 #
00016 # The Savane project is distributed in the hope that it will be useful,
00017 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 # GNU General Public License for more details.
00020 #
00021 # You should have received a copy of the GNU General Public License
00022 # along with the Savane project; if not, write to the Free Software
00023 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00024 
00025 
00026 # HELP: what we call now "query form" was previously called "report",
00027 # that name is still in the database.
00028 
00029 
00030 $is_admin_page='y';
00031 
00032 if (!$group_id) {
00033   exit_no_group();
00034 }
00035 
00036 if (!user_ismember($group_id,'A'))
00037 {
00038   exit_permission_denied();
00039 }
00040 
00041 # Initialize global bug structures
00042 trackers_init($group_id);
00043 
00044 if ($post_changes)
00045 {
00046 
00047   # scope is always project scope
00048   $rep_scope = "P";
00049 
00050   if ($update_report)
00051     {
00052       # Updat report name and description and delete old report entries
00053       $res = db_query("DELETE FROM ".ARTIFACT."_report_field WHERE report_id=$report_id");
00054       $res = db_query("UPDATE ".ARTIFACT."_report SET name='$rep_name', description='$rep_desc',scope='$rep_scope' WHERE report_id=$report_id");
00055     }
00056 
00057   else if ($create_report)
00058     {
00059       # Create a new report entry
00060       $res = db_query('INSERT INTO '.ARTIFACT.'_report (group_id,user_id,name,description,scope)'.
00061                       "VALUES ('$group_id','".user_getid()."','$rep_name',".
00062                       "'$rep_desc','$rep_scope')");
00063       $report_id = db_insertid($res);
00064     }
00065 
00066   # And now insert all the field entries in the trackers_report_field table
00067   $sql = 'INSERT INTO '.ARTIFACT.'_report_field (report_id, field_name,'.
00068      'show_on_query,show_on_result,place_query,place_result,col_width) VALUES ';
00069 
00070   while ( $field = trackers_list_all_fields() )
00071     {
00072 
00073       $cb_search = 'CBSRCH_'.$field;
00074       $cb_report = 'CBREP_'.$field;
00075       $tf_search = 'TFSRCH_'.$field;
00076       $tf_report = 'TFREP_'.$field;
00077       $tf_colwidth = 'TFCW_'.$field;
00078 
00079       if ($$cb_search || $$cb_report || $$tf_search || $$tf_report)
00080         {
00081 
00082           $cb_search_val = ($$cb_search ? '1':'0');
00083           $cb_report_val = ($$cb_report ? '1':'0');
00084           $tf_search_val = ($$tf_search ? '\''.$$tf_search.'\'' : 'NULL');
00085           $tf_report_val = ($$tf_report ? '\''.$$tf_report.'\'' : 'NULL');
00086           $tf_colwidth_val = ($$tf_colwidth? '\''.$$tf_colwidth.'\'' : 'NULL');
00087           $sql .= "('$report_id','$field',$cb_search_val,$cb_report_val,".
00088              "$tf_search_val,$tf_report_val,$tf_colwidth_val),";
00089         }
00090     }
00091   $sql = substr($sql,0,-1);
00092   #print "<br /> DBG SQL = $sql";
00093 
00094   $res = db_query($sql);
00095   if ($res)
00096     {
00097       if ($create_report)
00098         {
00099           sprintf(_("Query Form '%s' created successfully"),$rep_name);
00100         }
00101       else
00102         {
00103           sprintf(_("Query Form '%s' updated successfully"),$rep_name);
00104         }
00105     }
00106   else
00107     {
00108       if ($create_report)
00109         {
00110           sprintf(_("Failed to create query form '%s'"),$rep_name);
00111         }
00112       else
00113         {
00114           sprintf(_("Failed to update query form '%s'"),$rep_name);
00115         }
00116     }
00117 
00118 } /* End of post_changes */
00119 
00120 else if ($delete_report)
00121 {
00122 
00123   db_query("DELETE FROM ".ARTIFACT."_report WHERE report_id=$report_id");
00124   db_query("DELETE FROM ".ARTIFACT."_report_field WHERE report_id=$report_id");
00125 
00126 }
00127 
00128 
00129 # Display the UI forms
00130 
00131 if ($new_report)
00132 {
00133 
00134   trackers_header_admin(array ('title'=>_("Create A New Query Form")));
00135 
00136   # display the table of all fields that can be included in the report
00137   $title_arr=array();
00138   $title_arr[]=_("Field Label");
00139   $title_arr[]=_("Description");
00140   $title_arr[]=_("Use as a Search Criteria");
00141   $title_arr[]=_("Rank on Search");
00142   $title_arr[]=_("Use as an Output Column");
00143   $title_arr[]=_("Rank on Output");
00144   $title_arr[]=_("Column width (optional)");
00145 
00146   print'
00147         <form action="'.$PHP_SELF.'" method="post">
00148            <input type="hidden" name="create_report" value="y" />
00149            <input type="hidden" name="group_id" value="'.$group_id.'" />
00150            <input type="hidden" name="post_changes" value="y" />
00151            <p>
00152            <span class="preinput">'
00153     ._("Name of the Query Form:").'</span><br />
00154            <input type="text" name="rep_name" value="" size="20" maxlength="20" />
00155            </p><p>
00156            <span class="preinput">'
00157     ._("Scope").':</span><br />';
00158 
00159 # Separation of personal and project administration operation
00160 #  if (user_ismember($group_id,'A')
00161 #    {
00162 #      print '<select name="rep_scope">
00163 #                        <option value="I">'._("Personal").'</option>
00164 #                        <option value="P">'._("Project").'</option>
00165 #                        </select>';
00166 #    }
00167 #  else
00168 #    { print _("Personal").' <input type="hidden" name="rep_scope" value="I" />'; }
00169        print _("Project").' <input type="hidden" name="rep_scope" value="P" />';
00170 
00171 
00172 
00173   print ' </p><p>
00174             <span class="preinput">'._("Description:").'</span><br />
00175              <input type="text" name="rep_desc" value="" size="50" maxlength="120" />
00176                   </p>';
00177 
00178   print html_build_list_table_top ($title_arr);
00179   $i=0;
00180   while ( $field = trackers_list_all_fields() )
00181     {
00182 
00183       # Do not show fields not used by the project
00184       if ( !trackers_data_is_used($field))
00185         { continue; }
00186 
00187       # Do not show some special fields any way
00188       if (trackers_data_is_special($field))
00189         {
00190           if ( ($field == 'group_id') ||
00191                ($field == 'comment_type_id') )
00192             { continue; }
00193         }
00194 
00195       $cb_search = 'CBSRCH_'.$field;
00196       $cb_report = 'CBREP_'.$field;
00197       $tf_search = 'TFSRCH_'.$field;
00198       $tf_report = 'TFREP_'.$field;
00199       $tf_colwidth = 'TFCW_'.$field;
00200       print '<TR class="'. utils_get_alt_row_color($i) .'">';
00201 
00202       print "\n<td>".trackers_data_get_label($field).'</td>'.
00203         "\n<td>".trackers_data_get_description($field).'</td>'.
00204         "\n<td align=\"center\">".'<input type="checkbox" name="'.$cb_search.'" value="1" /></td>'.
00205         "\n<td align=\"center\">".'<input type="text" name="'.$tf_search.'" value="" size="5" maxlen="5" /></td>';
00206       
00207      # If the current field is item id, we force it's presence on the report
00208      # with rank 0. This field is mandatory: otherwise some links would be
00209      # broken or there would be even no links.
00210   if ($field == 'bug_id') 
00211    {
00212      print "\n<td align=\"center\"><input type=\"hidden\" name=\"".$cb_report."\" value=\"1\" />X</td>".
00213        "\n<td align=\"center\"><input type=\"hidden\" name=\"".$tf_report."\" value=\"0\" />0</td>";
00214    }
00215  else
00216    {
00217      print "\n<td align=\"center\">".'<input type="checkbox" name="'.$cb_report.'" value="1" '.$cb_report_chk.'  /></td>'.
00218        "\n<td align=\"center\">".'<input type="text" name="'.$tf_report.'" value="'.$tf_report_val.'" size="5" maxlen="5" /></td>';
00219    }
00220 
00221     print "\n<td align=\"center\">".'<input type="text" name="'.$tf_colwidth.'" value="" size="5" maxlen="5" /></td>'.
00222         '</tr>';
00223       $i++;
00224     }
00225   print '</table>'.
00226     '<p><center><input type="submit" name="submit" value="SUBMIT" /></center></p>'.
00227     '</form>';
00228 
00229 } else if ($show_report)
00230 {
00231 
00232 
00233   trackers_header_admin(array ('title'=>_("Modify a Query Form")));
00234 
00235   # fetch the report to update
00236   $sql = "SELECT * FROM ".ARTIFACT."_report WHERE report_id=$report_id";
00237   $res=db_query($sql);
00238   $rows = db_numrows($res);
00239   if (!$rows)
00240     {
00241       exit_error('Error',"Unknown Report ID ($report_id)");
00242     }
00243 
00244   # make sure this user has the right to modify the bug report
00245   if ( (db_result($res,0,'scope') == 'P') &&
00246        !user_ismember($group_id,'A'))
00247     {
00248       exit_permission_denied();
00249     }
00250 
00251   $sql_fld = "SELECT * FROM ".ARTIFACT."_report_field WHERE report_id=$report_id";
00252   $res_fld=db_query($sql_fld);
00253 
00254   # Build the list of fields involved in this report
00255   while ( $arr = db_fetch_array($res_fld) )
00256     {
00257       $fld[$arr['field_name']] = $arr;
00258     }
00259 
00260   # display the table of all fields that can be included in the report
00261   # along with their current state in this report
00262   $title_arr=array();
00263   $title_arr[]=_("Field Label");
00264   $title_arr[]=_("Description");
00265   $title_arr[]=_("Use as a Search Criteria");
00266   $title_arr[]=_("Rank on Search");
00267   $title_arr[]=_("Use as an Output Column");
00268   $title_arr[]=_("Rank on Output");
00269   $title_arr[]=_("Column width (optional)");
00270 
00271   print '<form action="'.$PHP_SELF.'" method="post">
00272            <input type="hidden" name="update_report" value="y" />
00273            <input type="hidden" name="group_id" value="'.$group_id.'" />
00274            <input type="hidden" name="report_id" value="'.$report_id.'" />
00275            <input type="hidden" name="post_changes" value="y" />
00276            <span class="preinput">'._("Name:").' </span><br />&nbsp;&nbsp;&nbsp;
00277            <input type="text" name="rep_name" value="'.db_result($res,0,'name').'" size="20" maxlength="20" />';
00278 
00279 
00280  #                &nbsp;&nbsp;&nbsp;&nbsp;<strong>'._("Scope:").' </strong>';
00281   #$scope = db_result($res,0,'scope');
00282   #if (user_ismember($group_id,'A'))
00283   #  print '<SELECT NAME="rep_scope">
00284   #                      <option value="i"'.($scope=='i' ? 'selected':'').'>'._("Personal").'</option>
00285   #                      <option value="p"'.($scope=='p' ? 'selected':'').'>'._("Project").'</option>
00286   #                      </select>';
00287   #else
00288   #  print ($scope=='P' ? 'Project':'Personal').
00289   #    '<input type="hidden" name="rep_scope" value="'.$scope.'" />';
00290 
00291   print '
00292             <p>
00293                <span class="preinput">'._("Description:").'</span><br />&nbsp;&nbsp;&nbsp;
00294             <input type="text" name="rep_desc" value="'.db_result($res,0,'description').'" size="50" maxlength="120" /></p>
00295                   <p>';
00296 
00297   print html_build_list_table_top ($title_arr);
00298   $i=0;
00299   while ( $field = trackers_list_all_fields() )
00300     {
00301 
00302       # Do not show fields not used by the project
00303       if ( !trackers_data_is_used($field))
00304         { continue; }
00305 
00306       # Do not show some special fields any way
00307       if (trackers_data_is_special($field))
00308         {
00309           if ( ($field == 'group_id') ||
00310                ($field == 'comment_type_id') )
00311             { continue; }
00312         }
00313 
00314       $cb_search = 'CBSRCH_'.$field;
00315       $cb_report = 'CBREP_'.$field;
00316       $tf_search = 'TFSRCH_'.$field;
00317       $tf_report = 'TFREP_'.$field;
00318       $tf_colwidth = 'TFCW_'.$field;
00319 
00320       $cb_search_chk = ($fld[$field]['show_on_query'] ? 'checked="checked"':'');
00321       $cb_report_chk = ($fld[$field]['show_on_result'] ? 'checked="checked"':'');
00322       $tf_search_val = $fld[$field]['place_query'];
00323       $tf_report_val = $fld[$field]['place_result'];
00324       $tf_colwidth_val = $fld[$field]['col_width'];
00325 
00326       print '<tr class="'. utils_get_alt_row_color($i) .'">';
00327 
00328       print "\n<td>".trackers_data_get_label($field).'</td>'.
00329         "\n<td>".trackers_data_get_description($field).'</td>'.
00330         "\n<td align=\"center\">".'<input type="checkbox" name="'.$cb_search.'" value="1" '.$cb_search_chk.'  /></td>'.
00331         "\n<td align=\"center\">".'<input type="text" name="'.$tf_search.'" value="'.$tf_search_val.'" size="5" maxlen="5" /></td>';
00332      # If the current field is item id, we force it's presence on the report
00333 # with rank 0. This field is mandatory: otherwise some links would be
00334      # broken or there would be even no links.
00335  if ($field == 'bug_id') 
00336    {
00337      print "\n<td align=\"center\"><input type=\"hidden\" name=\"".$cb_report."\" value=\"1\" />X</td>".
00338        "\n<td align=\"center\"><input type=\"hidden\" name=\"".$tf_report."\" value=\"0\" />0</td>";
00339    }
00340  else
00341    {
00342      print "\n<td align=\"center\">".'<input type="checkbox" name="'.$cb_report.'" value="1" '.$cb_report_chk.'  /></td>'.
00343        "\n<td align=\"center\">".'<input type="text" name="'.$tf_report.'" value="'.$tf_report_val.'" size="5" maxlen="5" /></td>';
00344    }
00345      print "\n<td align=\"center\">".'<input type="text" name="'.$tf_colwidth.'" value="'.$tf_colwidth_val.'" size="5" maxlen="5" /></td>'.
00346        '</tr>';
00347       $i++;
00348     }
00349   print '</table>'.
00350     '<p><center><input type="submit" name="submit" value="'._("Submit").'" /></center>'.
00351     '</form>';
00352 
00353 }
00354 else
00355 {
00356 
00357   # Front page
00358   trackers_header_admin(array ('title'=>_("Manage Query Forms")));
00359 
00360   #    print '<h2>'._("Manage Bug Reports").' '.help_button('trackers_admin_report_list',false).'</h2>';
00361 
00362   $sql = "SELECT * FROM ".ARTIFACT."_report WHERE group_id=$group_id ".
00363      ' AND (user_id='.user_getid().' OR scope=\'P\')';
00364   $res=db_query($sql);
00365   $rows = db_numrows($res);
00366   #print "<br /> DBG sql = $sql";
00367 
00368   if ($rows)
00369     {
00370       # Loop through the list of all bug report
00371       $title_arr=array();
00372       $title_arr[]=_("Id");
00373       $title_arr[]=_("Query form name");
00374       $title_arr[]=_("Description");
00375       $title_arr[]=_("Scope");
00376       $title_arr[]=_("Delete?");
00377 
00378       print "\n<h3>"._("Existing Query Forms:").'</h3>';
00379       print '<p>('._("Click to modify").')';
00380       print html_build_list_table_top ($title_arr);
00381       $i=0;
00382       while ($arr = db_fetch_array($res))
00383         {
00384 
00385           print '<tr class="'. utils_get_alt_row_color($i) .'"><td>';
00386 
00387           if ( ($arr['scope']=='P') && !user_ismember($group_id,'A') )
00388             {
00389               print $arr['report_id'];
00390               print "</td>\n<td>".$arr['name'].'</td>';
00391             }
00392           else
00393             {
00394               print '<a href="'.$PHP_SELF.'?group='.$group_name.
00395                 '&show_report=1&report_id='.$arr['report_id'].'">'.
00396                 $arr['report_id'].'</a>';
00397               print "</td>\n";
00398               print '<td><a href="'.$PHP_SELF.'?group='.$group_name.
00399                 '&show_report=1&report_id='.$arr['report_id'].'">'.
00400                 $arr['name'].'</a></td>';
00401             }
00402 
00403           print "\n<td>".$arr['description'].'</td>'.
00404             "\n<td align=\"center\">".(($arr['scope']=='P') ? _("Project"):_("Personal")).'</td>'.
00405             "\n<td align=\"center\">";
00406 
00407           if ( ($arr['scope']=='P') && !user_ismember($group_id,'A') )
00408             {
00409               print '-';
00410             }
00411           else
00412             {
00413               print '<a href="'.$PHP_SELF.'?group='.$group_name.
00414                 '&delete_report=1&report_id='.$arr['report_id'].
00415                 '" onClick="return confirm(\'Delete this Query Form?\')">'.
00416                 '<img src="'.$GLOBALS['sys_home'].'images/'.SV_THEME.'.theme/trash.png" border="0" /></A>';
00417             }
00418 
00419           print '</td></tr>';
00420           $i++;
00421         }
00422       print '</table>';
00423     }
00424   else
00425     {
00426       print '<h3>'._("No query form defined yet.").'</h3>';
00427     }
00428 
00429   printf ('<p>'._("You can %s create a new query form%s").'</p>','<a href="'.$PHP_SELF.'?group='.$group_name.'&new_report=1">','</a>');
00430 }
00431 
00432 trackers_footer(array());
00433 
00434 ?>

Generated on Sun Feb 26 13:23:03 2006 for Savane PHP Frontend Developer Reference by  doxygen 1.4.4