4 * Copyright (C) 2006 Alain Peyrat, Alcatel-Lucent
5 * Copyright (C) 2010 Alain Peyrat <aljeux@free.fr>
6 * Copyright (C) 2012 Alain Peyrat - Alcatel-Lucent
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * Standard Alcatel-Lucent disclaimer for contributing to open source
28 * "The provided file ("Contribution") has not been tested and/or
29 * validated for release as or in products, combinations with products or
30 * other commercial use. Any use of the Contribution is entirely made at
31 * the user's own responsibility and the user can not rely on any features,
32 * functionalities or performances Alcatel-Lucent has attributed to the
35 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
36 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
37 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
38 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
39 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
40 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
41 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
42 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
43 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
47 require_once dirname(__FILE__)."/../../env.inc.php";
48 require_once $gfcommon.'include/pre.php';
49 require_once $gfcommon.'forum/ForumFactory.class.php';
50 require_once $gfcommon.'tracker/ArtifactFactory.class.php';
51 require_once $gfcommon.'mail/MailingListFactory.class.php';
52 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
53 require_once $gfcommon.'survey/SurveyFactory.class.php';
55 function getAvailableBlocks($group) {
57 'summary_description' =>
58 _("Block to replace the default project description with an enhanced one."),
60 _("Block to list informations requested to ask to join a project"),
63 if ($group->usesForum()) {
64 // Get the blocks in the forums.
65 $blocks['forum index'] = _("Display block at the top of the listing");
66 $ff = new ForumFactory($group);
67 foreach ( $ff->getForums() as $f) {
68 $blocks['forum_'.$f->getName()] = _("Display block at the top");
72 if ($group->usesTracker()) {
73 // Get the blocks in the trackers.
74 $blocks['tracker index'] = _("Display block at the top of the listing");
75 $ff = new ArtifactTypeFactory($group);
76 foreach ( $ff->getArtifactTypes() as $f) {
77 $blocks['tracker_'.$f->getName()] = _("Display block at the top");
81 if ($group->usesMail()) {
82 // Get the blocks in the mailing lists.
83 $blocks['mail index'] = _("Display block at the top of the listing");
84 $ff = new MailingListFactory($group);
85 foreach ( $ff->getMailingLists() as $f) {
86 $blocks['mail_'.$f->getName()] = _("Display block at the top");
90 if ($group->usesPM()) {
91 // Get the blocks in the tasks.
92 $blocks['tasks index'] = _("Display block at the top of the listing");
93 $ff = new ProjectGroupFactory($group);
94 foreach ( $ff->getProjectGroups() as $f) {
95 $blocks['tasks_'.$f->getName()] = _("Display block at the top");
99 if ($group->usesDocman()) {
100 // Get the blocks in the doc.
101 $blocks['doc index'] = _("Display block at the top of the listing");
102 $blocks['doc help'] = _("Display block at the top of the main page");
105 if ($group->usesSurvey()) {
106 // Get the blocks in the survey.
107 $blocks['survey index'] = _("Display block at the top of the listing");
108 $ff = new SurveyFactory($group);
109 foreach ( $ff->getSurveys() as $f) {
110 $blocks['survey_'.$f->getTitle()] = _("Display block at the top");
114 if ($group->usesNews()) {
115 // Get the blocks in the news.
116 $blocks['news index'] = _("Display block at the top of the listing");
119 if ($group->usesSCM()) {
120 // Get the blocks in the scm.
121 $blocks['scm index'] = _("Display block at the top of the listing");
124 if ($group->usesFRS()) {
125 // Get the blocks in the files.
126 $blocks['files index'] = _("Display block at the top of the listing");
132 // the header that displays for the user portion of the plugin
133 function blocks_Project_Header($params) {
135 $params['toptab']='blocks';
136 $params['group']=$id;
138 Show horizontal links
140 site_project_header($params);
143 $type = getStringFromRequest('type');
144 $id = getStringFromRequest('id');
145 $pluginname = getStringFromRequest('pluginname');
146 $name = getStringFromRequest('name');
147 $body = getHtmlTextFromRequest('body');
148 $activate = getArrayFromRequest('activate');
150 $blocks_text = array(
151 'forum' => _('Forums'),
152 'tracker' => _('Trackers'),
153 'mail' => _('Lists'),
154 'tasks' => _('Tasks'),
156 'survey' => _('Surveys'),
159 'files' => _('Files')
163 exit_error(_('Cannot Process your request: No TYPE specified'),'home'); // you can create items in Base.tab and customize this messages
165 exit_error(_('Cannot Process your request: No ID specified'),'home');
168 $group = group_get_object($id);
172 if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the blocks plugin active
173 exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
176 session_require_perm ('project_admin', $id) ;
178 if ($type == 'admin') {
179 blocks_Project_Header(array('title'=>'Blocks Administration','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
181 $res = db_query_params('SELECT name, status FROM plugin_blocks WHERE group_id=$1',
183 while ($row = db_fetch_array($res)) {
184 $status[ $row['name'] ] = $row['status'];
187 print _("Blocks are customizable HTML boxes in the left or right side of the pages the web site. They are created manually.");
189 print "<form action=\"/plugins/blocks/\" method=\"post\">";
190 print "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
191 print "<input type=\"hidden\" name=\"pluginname\" value=\"$pluginname\" />\n";
192 print "<input type=\"hidden\" name=\"type\" value=\"admin_post\" />\n";
194 print "<table class=\"centered listing\">";
195 print "<thead><tr><th>".
208 $blocks = getAvailableBlocks($group);
210 foreach ($blocks as $b => $help) {
212 $class = ($class == 'even') ? "odd" : "even";
215 if (preg_match('/(.*) index$/', $b, $match)) {
216 print '<tr><td colspan="4"><b>'.$blocks_text[$match[1]].'</b></td></tr>';
219 $checked = (isset($status[$b]) && $status[$b] == 1) ? ' checked="checked"' : '';
221 print "<tr class=\"$class\"><td>$b</td>\n" .
222 "<td class=\"align-center\">" .
223 "<input type=\"checkbox\" name=\"activate[$b]\" value=\"1\"$checked /></td>\n" .
225 "<td><a href=\"/plugins/blocks/index.php?id=$id&type=configure&pluginname=blocks&name=".urlencode($b)."\">"._('Configure')."</a></td>\n</tr>\n";
228 print '<p class="align-center"><input type="submit" value="' .
232 } elseif ($type == 'admin_post') {
233 $res = db_query_params('SELECT name, status FROM plugin_blocks WHERE group_id=$1',
235 while ($row = db_fetch_array($res)) {
236 $present[ $row['name'] ] = true;
237 $status[ $row['name'] ] = $row['status'];
239 $blocks = getAvailableBlocks($group);
241 // Workaround when a block has a name with a & inside.
242 // It seems sadly converted by the form (or php?).
243 foreach ($activate as $k => $v) {
244 $nk = str_replace("&","&", $k);
247 unset($activate[$k]);
251 foreach ($blocks as $b => $help) {
256 if ((!isset($status[$b]) && $activate[$b]) ||
257 (isset($status[$b]) && $activate[$b] !== $status[$b]))
259 if (!isset($present[$b])) {
260 db_query_params('INSERT INTO plugin_blocks (group_id, name, status)
261 VALUES ($1, $2, $3)',
262 array($id, $b, $activate[$b]));
264 db_query_params('UPDATE plugin_blocks SET status=$1
265 WHERE group_id=$2 AND name=$3',
266 array($activate[$b], $id, $b));
269 $msg = _('Block Saved');
270 session_redirect('/plugins/blocks/index.php?id='.$id.'&type=admin&pluginname=blocks&feedback='.urlencode($msg));
271 } elseif ($type == 'configure') {
272 blocks_Project_Header(array('title'=>'Edit Block','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
273 // DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
275 $blocks = getAvailableBlocks($group);
276 $res = db_query_params('SELECT content FROM plugin_blocks WHERE group_id=$1 AND name=$2',
278 $body = db_result($res,0,"content");
280 print _("Edit the block as you want. If you activate the HTML editor, you will be able to use WYSIWYG formatting (bold, colors...)");
282 print '<div class="align-center">';
283 print "<p><b>$blocks[$name]</b> ($name)</p>";
284 print "<form action=\"/plugins/blocks/\" method=\"post\">";
285 print "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
286 print "<input type=\"hidden\" name=\"pluginname\" value=\"$pluginname\" />\n";
287 print "<input type=\"hidden\" name=\"type\" value=\"configure_post\" />\n";
288 print "<input type=\"hidden\" name=\"name\" value=\"$name\" />\n";
290 // Get default body from the templates defined in the config file.
292 $body = forge_get_config($name, 'blocks');
294 $body = forge_get_config('default', 'blocks');
296 $body = '{boxHeader}'._('Enter your text here').'{boxFooter}';
301 $params['body'] = $body;
302 $params['width'] = "800";
303 $params['height'] = "500";
304 $params['group'] = $id;
305 $params['content'] = '<textarea name="body" rows="20" cols="80">'.$body.'</textarea>';
307 if (util_is_html($body)) {
308 // If user is editing HTML, keep HTML format by saying it's html
309 $params['content'] = '<input type="hidden" name="_body_content_type" value="html" />'."\n".$params['content'];
312 plugin_hook_by_reference("text_editor", $params);
313 echo $params['content'];
315 print "<br /><input type=\"submit\" value=\"" .
321 print "<fieldset><legend>".
325 _("You can create boxes like the ones on the right site of summary page, by inserting the following sentences in the content:").
328 _(": will create the top part of the box using Hello as title.").
331 _(": will create a middle part of a box using Here as title (optional).").
334 _(": will create the end part of a box.").
335 "</li></ul><ul><li>".
337 _(": will create a header before a text.").
338 "</li><li>{boxFooter}".
339 _(": will create a footer after a text.").
341 _("You can create as many boxes as you want, but a boxTop has to be closed by a boxBottom and a boxHeader has to be closed by a boxFooter.").
344 } elseif ($type == 'configure_post') {
345 $res = db_query_params('SELECT id FROM plugin_blocks WHERE group_id=$1 AND name=$2',
347 if (db_numrows($res)== 0) {
348 db_query_params('INSERT INTO plugin_blocks (group_id, name, content)
349 VALUES ($1, $2, $3)',
350 array($id, $name, $body));
352 db_query_params('UPDATE plugin_blocks SET content=$1
353 WHERE group_id=$2 AND name=$3',
354 array($body, $id, $name));
356 $msg = $name .' : '. _('Block configuration saved');
357 session_redirect('/plugins/blocks/index.php?id='.$id.'&type=admin&pluginname=blocks&feedback='.urlencode($msg));
360 site_project_footer(array());