00001 <?php
00002 # This file is part of the Savane project
00003 # <http://gna.org/projects/savane/>
00004 #
00005 # $Id: votes.php 4645 2005-09-01 12:54:05Z toddy $
00006 #
00007 # Copyright 2005 (c) Mathieu Roy <yeupou--gnu.org>
00008 #
00009 # The Savane project is free software; you can redistribute it and/or
00010 # modify it under the terms of the GNU General Public License
00011 # as published by the Free Software Foundation; either version 2
00012 # of the License, or (at your option) any later version.
00013 #
00014 # The Savane project is distributed in the hope that it will be useful,
00015 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00017 # GNU General Public License for more details.
00018 #
00019 # You should have received a copy of the GNU General Public License
00020 # along with the Savane project; if not, write to the Free Software
00021 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00022
00027 function cookbook_audience_possiblevalues() {
00028 return array("anonymous" => _("Anonymous Users"),
00029 "loggedin" => _("Logged-in Users"),
00030 "members" => _("All Project Members"),
00031 "technicians" => _("Project Members who are technicians"),
00032 "managers" => _("Project Members who are managers"));
00033 }
00034
00039 function cookbook_context_project_possiblevalues() {
00040 return array("project" => _("Project Main Pages"),
00041 "homepage" => _("Project Homepage"),
00042 "cookbook" => _("Cookbook"),
00043 "download" => _("Download Area"),
00044 "support" => _("Support Tracker"),
00045 "bugs" => _("Bugs Tracker"),
00046 "task" => _("Task Manager"),
00047 "patch" => _("Patch Tracker"),
00048 "news" => _("News Manager"),
00049 "mail" => _("Mailing Lists"),
00050 "cvs" => _("Source Code Manager: CVS Repositories"),
00051 "arch" => _("Source Code Manager: GNU Arch Repositories"),
00052 "svn" => _("Source Code Manager: Subversion Repositories"));
00053 }
00054
00055 # Guess all the possible values in theory on the site for the site admin
00056 function cookbook_context_site_possiblevalues() {
00057 return array("my" => _("My (User Personal Area)"),
00058 "stats" => _("Site Statistics"),
00059 "siteadmin" => _("Site Administration"));
00060 }
00061
00062 # Guess all the impossible values in reality for a project
00063 function cookbook_context_project_impossiblevalues() {
00064 global $group_id;
00065
00066 # Site values are per definition impossible for a normal project
00067 $array_impossible = cookbook_context_site_possiblevalues();
00068
00069 # Impossible values are values of unactivated features for the project
00070 $array_possible = cookbook_context_project_possiblevalues();
00071 $project = project_get_object($group_id);
00072 while(list($feature,) = each($array_possible))
00073 {
00074 # Cookbook cannot be deactivated
00075 if ($feature == 'cookbook')
00076 { continue; }
00077
00078 # Project main pages cannot be deactivated
00079 if ($feature == 'project')
00080 { continue; }
00081
00082 if (!$project->Uses($feature))
00083 {
00084 $array_impossible[$feature] = 1;
00085 }
00086 }
00087
00088
00089 return $array_impossible;
00090 }
00091
00092
00093
00097 function cookbook_context_possiblevalues() {
00098 global $group_id, $sys_group_id;
00099
00100 # All projec-wide possible values, ordered in a clean way
00101 $array_possible = cookbook_context_project_possiblevalues();
00102
00103 if ($group_id != $sys_group_id)
00104 {
00105 # If we are in a normal group, remove impossible values.
00106 # For instance, remove all unused features
00107 $array_impossible = cookbook_context_project_impossiblevalues();
00108
00109 while(list($feature,) = each($array_impossible))
00110 {
00111 unset($array_possible[$feature]);
00112 }
00113 }
00114 else
00115 {
00116 # For the site admin group, present all possible values
00117 $array_possible = array_merge(cookbook_context_site_possiblevalues(),
00118 $array_possible);
00119 }
00120
00121
00122 reset($array_possible);
00123 return $array_possible;
00124 }
00125
00129 function cookbook_subcontext_possiblevalues() {
00130 return array("browsing" => _("Browsing"),
00131 "postitem" => _("Posting New Items"),
00132 "edititem" => _("Editing Items, Posting Comments"),
00133 "search" => _("Doing Searches"),
00134 "configure" => _("Configuring Features"));
00135 }
00136
00137
00138
00139
00143 function cookbook_build_form ($which="audience")
00144 {
00145 global $item_id, $group_id, $previous_form_bad_fields;
00146
00147 $possiblevalues = array();
00148 if ($which == "audience")
00149 {
00150 $possiblevalues = cookbook_audience_possiblevalues();
00151 }
00152 if ($which == "context")
00153 {
00154 $possiblevalues = cookbook_context_possiblevalues();
00155 }
00156 if ($which == "subcontext")
00157 {
00158 $possiblevalues = cookbook_subcontext_possiblevalues();
00159 }
00160
00161 # If there is an item id available, it means we are editing an item
00162 # and we want to previous results from the database
00163 if ($item_id)
00164 {
00165 $result = db_query("SELECT * FROM cookbook_context2recipe WHERE recipe_id='$item_id' AND group_id='$group_id' LIMIT 1");
00166 }
00167
00168 unset($content);
00169 while(list($field,$label) = each($possiblevalues))
00170 {
00171 unset($checked);
00172
00173 # Take into account database content
00174 if ($item_id && db_result($result, 0, $which."_".$field) == 1)
00175 { $checked = ' checked="checked"'; }
00176
00177 # Ultimately take into account what was posted, in the case the form
00178 # was reprovided to the user because he forgot mandatory fields
00179 if ($previous_form_bad_fields)
00180 {
00181 if (sane_post("recipe_".$which."_".$field) == true)
00182 { $checked = ' checked="checked"'; }
00183 else
00184 { unset($checked); }
00185 }
00186
00187 if (!defined('PRINTER'))
00188 {
00189 # Normal output
00190 $content .= '<input type="checkbox" name="recipe_'.$which.'_'.$field.'"'.$checked.' />'.$label.'<br />';
00191 }
00192 else
00193 {
00194 # Printer mode output, show only selected entries
00195 if ($checked)
00196 { $content .= $label.'<br />'; }
00197
00198 }
00199 }
00200
00201 # remove the extra line break
00202 $content = rtrim($content, '<br />');
00203
00204 return $content;
00205 }
00206
00210 function cookbook_describe ($which="audience")
00211 {
00212 unset($text);
00213 if ($which == "audience")
00214 {
00215 $text = _("Defines which users will actually get such recipe showing up as related recipe while browsing the site. It will not prevent other users to see the recipe in the big list inside the Cookbook.");
00216 }
00217 if ($which == "context")
00218 {
00219 $text = _("Defines on which pages such recipe will show up as related recipe. It will not prevent other users to see the recipe in the big list inside the Cookbook.");
00220 }
00221 if ($which == "subcontext")
00222 {
00223 $text = _("Defines while doing which actions such recipe will show up as related recipe. It will not prevent other users to see the recipe in the big list inside the Cookbook.");
00224 }
00225
00226 return $text;
00227 }
00228
00233 function cookbook_print_form ()
00234 {
00235 global $j, $fields_per_line, $i, $row_class, $field_class;
00236
00237 # Field getting one line for itself
00238 # | Audience |
00239
00240 # prepare next background color change
00241 $j++;
00242
00243 print "\n<tr".$row_class.">".
00244 '<td valign="middle" '.$field_class.' width="15%"><span class="preinput"><span class="help" title="'.cookbook_describe("audience").'">'._("Audience:").'</span></span></td>'.
00245 '<td valign="middle" '.$field_class.' colspan="'.(2*$fields_per_line-1).'" width="75%">'.
00246 cookbook_build_form("audience").'</td>'.
00247 "\n</tr>";
00248
00249 $i = 0;
00250
00251 # Field getting half of a line for itself
00252 # | context, kind of pages | context, kind of action
00253 # (CONTEXT) (SUBCONTEXT)
00254
00255 # Change background color
00256 unset($row_class);
00257 if ($j % 2)
00258 {
00259 $row_class = ' class="'.utils_altrow($j+1).'"';
00260 }
00261
00262 # prepare next background color change
00263 $j++;
00264
00265 print ($i % $fields_per_line ? '':"\n<tr".$row_class.">");
00266 print '<td valign="middle"'.$field_class.' width="15%"><span class="preinput"><span class="help" title="'.cookbook_describe("context").'">'._("Feature:").'</span></span></td><td valign="middle"'.$field_class.' width="35%">'.cookbook_build_form("context").'</td>';
00267 $i++;
00268 print ($i % $fields_per_line ? '':"\n</tr>");
00269 print ($i % $fields_per_line ? '':"\n<tr".$row_class.">");
00270 print '<td valign="middle"'.$field_class.' width="15%"><span class="preinput"><span class="help" title="'.cookbook_describe("subcontext").'">'._("Action:").'</span></span></td><td valign="middle"'.$field_class.' width="35%">'.cookbook_build_form("subcontext").'</td>';
00271 $i++;
00272 print ($i % $fields_per_line ? '':"\n</tr>");
00273
00274 $i = 0;
00275
00276 # Change background color
00277 unset($row_class);
00278 if ($j % 2)
00279 {
00280 $row_class = ' class="'.utils_altrow($j+1).'"';
00281 }
00282
00283 }
00284
00289 function cookbook_handle_update($item_id, $group_id)
00290 {
00291 global $change_exists;
00292
00293 ## Pass thru all the available/configurable fields
00294 unset($cookbook_upd_list);
00295
00296 # Find out the targetted audience
00297 $audience_cases = array();
00298 $possiblevalues = cookbook_audience_possiblevalues();
00299 while(list($field,) = each($possiblevalues))
00300 {
00301 $value = 0;
00302 if (sane_post("recipe_audience_".$field))
00303 { $value = 1; }
00304 $cookbook_upd_list .= "audience_$field='$value',";
00305 }
00306
00307 # Find out the targetted context (feature)
00308 $context_cases = array();
00309 $possiblevalues = cookbook_context_possiblevalues();
00310 while(list($field,) = each($possiblevalues))
00311 {
00312 $value = 0;
00313 if (sane_post("recipe_context_".$field))
00314 { $value = 1; }
00315 $cookbook_upd_list .= "context_$field='$value',";
00316 }
00317
00318
00319 # Find out the targetted subcontext (action)
00320 $subcontext_cases = array();
00321 $possiblevalues = cookbook_subcontext_possiblevalues();
00322 while(list($field,) = each($possiblevalues))
00323 {
00324 $value = 0;
00325 if (sane_post("recipe_subcontext_".$field))
00326 { $value = 1; }
00327 $cookbook_upd_list .= "subcontext_$field='$value',";
00328 }
00329
00330 # Create from scratch a row, to be able to do a simple update afterwards
00331 if (!db_numrows(db_query("SELECT context_id FROM cookbook_context2recipe WHERE recipe_id='$item_id' AND group_id='$group_id' LIMIT 1")))
00332 {
00333 db_query("INSERT INTO cookbook_context2recipe (recipe_id,group_id) VALUES ('$item_id','$group_id')");
00334 }
00335
00336 # Now do an update
00337 $cookbook_upd_list = rtrim($cookbook_upd_list, ",");
00338 $sql="UPDATE cookbook_context2recipe SET $cookbook_upd_list ".
00339 " WHERE recipe_id='$item_id' AND group_id='$group_id'";
00340 $result=db_affected_rows(db_query($sql));
00341
00342 # If there was affected rows, it means we did an update
00343 # (ignoring the very unusual case where the SQL would fail)
00344 if ($result)
00345 {
00346 $change_exists = 1;
00347 fb(_("Audience/Feature/Action updated"));
00348 trackers_data_add_history("Audience/Feature/Action",
00349 '',
00350 '',
00351 $item_id);
00352
00353 }
00354 }
00355
00356
00357 ?>