00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: conf.php 5429 2006-02-17 22:59:20Z toddy $
00006 #
00007 # Copyright 2004-2004 (c) Mathieu Roy <yeupou--at--gnu.org>
00008 # Yves Perrin <yves.perrin--at--cern.ch>
00009 #
00010 # The Savane project is free software; you can redistribute it and/or
00011 # modify it under the terms of the GNU General Public License
00012 # as published by the Free Software Foundation; either version 2
00013 # of the License, or (at your option) any later version.
00014 #
00015 # The Savane project is distributed in the hope that it will be useful,
00016 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 # GNU General Public License for more details.
00019 #
00020 # You should have received a copy of the GNU General Public License
00021 # along with the Savane project; if not, write to the Free Software
00022 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00023
00024
00025 # This page should store function related to trackers configuration
00026 # (some of these are in general/data and should be moved here)
00027
00028
00029 # Copy for a given tracker the configuration of the tracker of another
00030 # project. This action is irreversible and can alter in an incoherent way
00031 # already posted items: it is supposed to be mainly used to configure a
00032 # new tracker. It can be used to keep several project using a coherent
00033 # configuration but it should not be used a trackers will divergeant
00034 # configuration already being used.
00035 #
00036 # To ease development, we ll make simple SQL query and we ll parse the
00037 # result. We ll be doing dumb code, code that we ll be able to debug.
00038 # (you need to be smarter than the code to be able to debug it, so lets avoid
00039 # writing the smartest code, so we still have a chance)
00040 function trackers_conf_copy ($group_id, $artifact, $from_group_id)
00041 {
00042 if (!$artifact || !$group_id || !$from_group_id)
00043 {
00044 # case that should never happen
00045 fb(_("Missing parameters"), 1);
00046 return 0;
00047 }
00048 fb(sprintf(_("Start copying configuration of group #%s %s tracker"),
00049 $from_group_id,
00050 $artifact));
00051
00052 # Copy the notification settings
00053 $res_groups_from_group = db_query("SELECT * FROM groups WHERE group_id='$from_group_id'");
00054 $sql = "UPDATE groups SET ".
00055 "new_".$artifact."_address='".db_result($res_groups_from_group,
00056 0,
00057 "new_".$artifact."_address")."', ".
00058 $artifact."_glnotif='".db_result($res_groups_from_group,
00059 0,
00060 $artifact."_glnotif")."', ".
00061 "send_all_".$artifact."='".db_result($res_groups_from_group,
00062 0,
00063 "send_all_".$artifact)."', ".
00064 $artifact."_private_exclude_address='".db_result($res_groups_from_group,
00065 0,
00066 $artifact."_private_excluded_address")."' ".
00067 "WHERE group_id='$group_id'";
00068
00069 if (db_affected_rows(db_query($sql)))
00070 { fb(_("Notification settings copied")); }
00071
00072 # Delete currently set field usage and field values
00073 # Copy the field usage and field values of the other project
00074 $sql = "DELETE FROM ".$artifact."_field_value WHERE group_id='$group_id'";
00075 if (db_affected_rows(db_query($sql)))
00076 { fb(_("Previous field values deleted")); }
00077 $sql = "DELETE FROM ".$artifact."_field_usage WHERE group_id='$group_id'";
00078 if (db_affected_rows(db_query($sql)))
00079 { fb(_("Previous field usage deleted")); }
00080
00081 $result_field_usage_from_group = db_query("SELECT * FROM ".$artifact."_field_usage WHERE group_id='$from_group_id'");
00082 $z = 0;
00083 unset($itemsdone);
00084 while ($thisone = db_fetch_array($result_field_usage_from_group))
00085 {
00086
00087 $sql = db_createinsertinto($result_field_usage_from_group,
00088 $artifact."_field_usage",
00089 $z,
00090 "none",
00091 "group_id",
00092 $group_id);
00093
00094 if (db_affected_rows(db_query($sql)))
00095 { $itemsdone .= "#".$thisone['bug_field_id']." "; }
00096
00097 $z++;
00098 }
00099 if ($itemsdone)
00100 { fb(sprintf(_("Field values %s copied"), $itemsdone)); }
00101
00102
00103 $result_field_value_from_group = db_query("SELECT * FROM ".$artifact."_field_value WHERE group_id='$from_group_id'");
00104 $z = 0;
00105 unset($itemsdone);
00106 while ($thisone = db_fetch_array($result_field_value_from_group))
00107 {
00108
00109 $sql = db_createinsertinto($result_field_value_from_group,
00110 $artifact."_field_value",
00111 $z,
00112 "bug_fv_id",
00113 "group_id",
00114 $group_id);
00115
00116 if (db_affected_rows(db_query($sql)))
00117 { $itemsdone .= "#".$thisone['bug_fv_id']." "; }
00118
00119 $z++;
00120 }
00121 if ($itemsdone)
00122 { fb(sprintf(_("Field values %s copied"), $itemsdone)); }
00123
00124
00125 # Delete currently set canned responses
00126 # Copy the canned responses of the other project
00127 $sql = "DELETE FROM ".$artifact."_canned_responses WHERE group_id='$group_id'";
00128 if (db_affected_rows(db_query($sql)))
00129 { fb(_("Previous canned responses deleted")); }
00130
00131 $result_canned_from_group = db_query("SELECT * FROM ".$artifact."_canned_responses WHERE group_id='$from_group_id'");
00132 $z = 0;
00133 unset($itemsdone);
00134 while ($thisone = db_fetch_array($result_canned_from_group))
00135 {
00136
00137 $sql = db_createinsertinto($result_canned_from_group,
00138 $artifact."_canned_responses",
00139 $z,
00140 "bug_canned_id",
00141 "group_id",
00142 $group_id);
00143
00144 if (db_affected_rows(db_query($sql)))
00145 { $itemsdone .= "#".$thisone['bug_canned_id']." "; }
00146
00147 $z++;
00148 }
00149 if ($itemsdone)
00150 { fb(sprintf(_("Canned responses %s copied"), $itemsdone)); }
00151
00152 # Delete currently set query forms
00153 # Copy the query forms of the other project
00154 $res_queryforms = db_query("SELECT * FROM ".$artifact."_report WHERE group_id='$group_id'");
00155 $sql = "DELETE FROM ".$artifact."_report WHERE group_id='$group_id'";
00156 if (db_affected_rows(db_query($sql)))
00157 { fb(_("Previous query forms deleted")); }
00158 while ($thisone = db_fetch_array($res_queryforms))
00159 {
00160 # Not verbose
00161 db_query("DELETE FROM ".$artifact."_report_field WHERE report_id='".$thisone['report_id']."'");
00162 }
00163
00164 $result_queryforms_from_group = db_query("SELECT * FROM ".$artifact."_report WHERE group_id='$from_group_id'");
00165 $z = 0;
00166 unset($itemsdone);
00167 while ($thisone = db_fetch_array($result_queryforms_from_group))
00168 {
00169 # Copy the report
00170 $sql = db_createinsertinto($result_queryforms_from_group,
00171 $artifact."_report",
00172 $z,
00173 "report_id",
00174 "group_id",
00175 $group_id);
00176 $thisone_id = db_insertid(db_query($sql));
00177 if ($thisone_id)
00178 {
00179 $itemsdone .= "#".$thisone['report_id']." ";
00180
00181 # Copy the info related to the report in report_field
00182 $result_thisqueryforms_from_group = db_query("SELECT * FROM ".$artifact."_report_field WHERE report_id='".$thisone['report_id']."'");
00183 $y = 0;
00184 while ($thisonequery = db_fetch_array($result_thisqueryforms_from_group))
00185 {
00186 $sql = db_createinsertinto($result_thisqueryforms_from_group,
00187 $artifact."_report_field",
00188 $y,
00189 "none",
00190 "report_id",
00191 $thisone_id);
00192
00193 # Silent: if we list even these insert, the feedback will
00194 # be unreadable, too long
00195 db_query($sql);
00196
00197 $y++;
00198 }
00199
00200 }
00201
00202 $z++;
00203 }
00204 if ($itemsdone)
00205 { fb(sprintf(_("Query forms %s copied"), $itemsdone)); }
00206
00207
00208 # Delete current set transitions
00209 # Copy the transition of the other project
00210 $res_transitions= db_query("SELECT * FROM trackers_field_transition WHERE group_id='$group_id' AND artifact='$artifact'");
00211 $sql = "DELETE FROM trackers_field_transition WHERE group_id='$group_id' AND artifact='$artifact'";
00212 if (db_affected_rows(db_query($sql)))
00213 { fb(_("Previous field transitions deleted")); }
00214 while ($thisone = db_fetch_array($res_transitions))
00215 {
00216 # Not verbose
00217 db_query("DELETE FROM trackers_field_transition_other_field_update WHERE transition_id='".$thisone['transition_id']."'");
00218 }
00219
00220 $result_transitions_from_group = db_query("SELECT * FROM trackers_field_transition WHERE artifcat='$artifact' AND group_id='$from_group_id'");
00221 $z = 0;
00222 unset($itemsdone);
00223 while ($thisone = db_fetch_array($result_transitions_from_group))
00224 {
00225 # Copy the report
00226 $sql = db_createinsertinto($result_transitions_from_group,
00227 "trackers_field_transition",
00228 $z,
00229 "transition_id",
00230 "group_id",
00231 $group_id);
00232 $thisone_id = db_insertid(db_query($sql));
00233 if ($thisone_id)
00234 {
00235 $itemsdone .= "#".$thisone['transition_id']." ";
00236
00237 # Copy the info related to the report in report_field
00238 $result_thistransitions_from_group = db_query("SELECT * FROM trackers_field_transition_other_field_update WHERE transition_id='".$thisone['transition_id']."'");
00239 $y = 0;
00240 while ($thisonequery = db_fetch_array($result_thistransitions_from_group))
00241 {
00242 $sql = db_createinsertinto($result_thistransitions_from_group,
00243 "trackers_field_transition_other_field_update",
00244 $y,
00245 "other_field_update_id",
00246 "report_id",
00247 $thisone_id);
00248
00249 # Silent: if we list even these insert, the feedback will
00250 # be unreadable, too long
00251 db_query($sql);
00252
00253 $y++;
00254 }
00255
00256 }
00257
00258 $z++;
00259 }
00260 if ($itemsdone)
00261 { fb(sprintf(_("Transitions %s copied"), $itemsdone)); }
00262
00263
00264
00265 fb(_("Configuration copy finished"));
00266
00267 }
00268
00269
00270
00271 function conf_form ($group_id, $artifact)
00272 {
00273
00274 $result = db_query("SELECT groups.group_name,"
00275 . "groups.group_id "
00276 . "FROM groups,user_group "
00277 . "WHERE groups.group_id=user_group.group_id "
00278 . "AND user_group.user_id='". user_getid() ."' "
00279 . "AND groups.status='A' "
00280 . "AND groups.use_".$artifact."='1'");
00281
00282 $vals = array();
00283 $texts = array();
00284 unset($found);
00285 while ($thisgroup = db_fetch_array($result))
00286 {
00287 $vals[] = $thisgroup['group_id'];
00288 $texts[] = $thisgroup['group_name'];
00289 $found = 1;
00290 }
00291
00292
00293 if ($found)
00294 {
00295 print '<p>'.sprintf(_("You can copy the configuration of the %s tracker of the following projects (this list was established according to your currently membership record)."), $artifact).'</p>
00296 <p class="warn">'._("Beware, your current configuration will be irremediably lost.").'</p>
00297
00298 <form action="'.$PHP_SELF.'" method="post">
00299 <input type="hidden" name="group_id" value="'.$group_id.'" />
00300 <input type="hidden" name="artifact" value="'.$artifact.'" />
00301 <span class="preinput">'._("Projects:").'</span><br />
00302
00303 ';
00304
00305 print html_build_select_box_from_arrays($vals, $texts,'from_group_id');
00306
00307 print form_footer();
00308
00309 }
00310 else
00311 {
00312 print '<p>'.sprintf(_("You cannot copy the configuration of other projects because you are not member of any project hosted here that uses a %s tracker"), $artifact).'</p>';
00313 }
00314
00315 }
00316
00317 ?>