3 * Copyright (C) 2006 Alain Peyrat, Alcatel-Lucent
4 * Copyright (C) 2010 Alain Peyrat <aljeux@free.fr>
5 * Copyright (C) 2012-2014 Alain Peyrat - Alcatel-Lucent
6 * Copyright 2016, Franck Villaume - TrivialDev
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';
57 function getAvailableBlocks($group) {
59 'summary_description' =>
60 _("Block to replace the default project description with an enhanced one."),
62 _("Block to list informations requested to ask to join a project"),
65 if ($group->usesForum()) {
66 // Get the blocks in the forums.
67 $blocks['forum index'] = _("Display block at the top of the listing");
68 $ff = new ForumFactory($group);
69 foreach ( $ff->getForums() as $f) {
70 $blocks['forum_'.$f->getName()] = _("Display block at the top");
74 if ($group->usesTracker()) {
75 // Get the blocks in the trackers.
76 $blocks['tracker index'] = _("Display block at the top of the listing");
77 $ff = new ArtifactTypeFactory($group);
78 foreach ( $ff->getArtifactTypes() as $f) {
79 $blocks['tracker_'.$f->getName()] = _("Display block at the top");
83 if ($group->usesMail()) {
84 // Get the blocks in the mailing lists.
85 $blocks['mail index'] = _("Display block at the top of the listing");
86 $ff = new MailingListFactory($group);
87 foreach ( $ff->getMailingLists() as $f) {
88 $blocks['mail_'.$f->getName()] = _("Display block at the top");
92 if ($group->usesPM()) {
93 // Get the blocks in the tasks.
94 $blocks['tasks index'] = _("Display block at the top of the listing");
95 $ff = new ProjectGroupFactory($group);
96 foreach ( $ff->getProjectGroups() as $f) {
97 $blocks['tasks_'.$f->getName()] = _("Display block at the top");
101 if ($group->usesDocman()) {
102 // Get the blocks in the doc.
103 $blocks['doc index'] = _("Display block at the top of the listing");
104 $blocks['doc help'] = _("Display block at the top of the main page");
107 if ($group->usesSurvey()) {
108 // Get the blocks in the survey.
109 $blocks['survey index'] = _("Display block at the top of the listing");
110 $ff = new SurveyFactory($group);
111 foreach ( $ff->getSurveys() as $f) {
112 $blocks['survey_'.$f->getTitle()] = _("Display block at the top");
116 if ($group->usesNews()) {
117 // Get the blocks in the news.
118 $blocks['news index'] = _("Display block at the top of the listing");
121 if ($group->usesSCM()) {
122 // Get the blocks in the scm.
123 $blocks['scm index'] = _("Display block at the top of the listing");
126 if ($group->usesFRS()) {
127 // Get the blocks in the files.
128 $blocks['files index'] = _("Display block at the top of the listing");
134 // the header that displays for the user portion of the plugin
135 function blocks_Project_Header($params) {
137 $params['toptab']='blocks';
138 $params['group']=$id;
140 Show horizontal links
142 site_project_header($params);
145 $type = getStringFromRequest('type');
146 $id = getIntFromRequest('id');
147 $pluginname = getStringFromRequest('pluginname');
148 $name = getStringFromRequest('name');
149 $body = getHtmlTextFromRequest('body');
150 $activate = getArrayFromRequest('activate');
152 $blocks_text = array(
153 'forum' => _('Forums'),
154 'tracker' => _('Trackers'),
155 'mail' => _('Lists'),
156 'tasks' => _('Tasks'),
158 'survey' => _('Surveys'),
161 'files' => _('Files')
165 exit_error(_('Cannot Process your request')._(': ')._('No TYPE specified'), 'home'); // you can create items in Base.tab and customize this messages
167 exit_error(_('Cannot Process your request')._(': ')._('No ID specified'), 'home');
170 $group = group_get_object($id);
174 if (!$group->usesPlugin($pluginname)) {//check if the group has the blocks plugin active
175 exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'), $pluginname), 'home');
178 session_require_perm ('project_admin', $id) ;
180 if ($type == 'admin') {
181 blocks_Project_Header(array('title' => _('Blocks Administration'), 'pagename' => $pluginname, 'sectionvals' => array(group_getname($id))));
183 $res = db_query_params('SELECT name, status FROM plugin_blocks WHERE group_id=$1',
185 while ($row = db_fetch_array($res)) {
186 $status[ $row['name'] ] = $row['status'];
189 print _("Blocks are customizable HTML boxes in the left or right side of the pages the web site. They are created manually.");
190 echo $HTML->openForm(array('action' => '/plugins/blocks/', 'method' => 'post'));
191 echo html_e('input', array('type' => 'hidden', 'name' => 'id', 'value' => $id));
192 echo html_e('input', array('type' => 'hidden', 'name' => 'pluginname', 'value' => $pluginname));
193 echo html_e('input', array('type' => 'hidden', 'name' => 'type', 'value' => 'admin_post'));
195 $thArray = array(_('Name'), _('Active'), _('Description'), _('Operation'));
196 echo $HTML->listTableTop($thArray, array(), 'centered listing');
197 $blocks = getAvailableBlocks($group);
198 foreach ($blocks as $b => $help) {
200 if (preg_match('/(.*) index$/', $b, $match)) {
202 $cells[] = array(html_e('strong', array(), $blocks_text[$match[1]]), 'colspan' => 4);
203 echo $HTML->multiTableRow(array(), $cells);
207 $inputAttr = array('type' => 'checkbox', 'name' => 'activate['.$b.']', 'value' => 1);
208 if (isset($status[$b]) && $status[$b] == 1) {
209 $inputAttr['checked'] = 'checked';
211 $cells[] = array(html_e('input', $inputAttr), 'class' => 'align-center');
213 $cells[][] = util_make_link('/plugins/blocks/?id='.$id.'&type=configure&pluginname=blocks&name='.urlencode($b), _('Configure'));
214 echo $HTML->multiTableRow(array(), $cells);
216 echo $HTML->listTableBottom();
217 print '<p class="align-center"><input type="submit" value="' .
220 echo $HTML->closeForm();
221 } elseif ($type == 'admin_post') {
222 $res = db_query_params('SELECT name, status FROM plugin_blocks WHERE group_id=$1',
224 while ($row = db_fetch_array($res)) {
225 $present[ $row['name'] ] = true;
226 $status[ $row['name'] ] = $row['status'];
228 $blocks = getAvailableBlocks($group);
230 // Workaround when a block has a name with a & inside.
231 // It seems sadly converted by the form (or php?).
232 foreach ($activate as $k => $v) {
233 $nk = str_replace("&","&", $k);
236 unset($activate[$k]);
240 foreach ($blocks as $b => $help) {
241 if (!isset($activate[$b])) {
244 if ((!isset($status[$b]) && $activate[$b]) ||
245 (isset($status[$b]) && $activate[$b] !== $status[$b])) {
247 if (!isset($present[$b])) {
248 db_query_params('INSERT INTO plugin_blocks (group_id, name, status)
249 VALUES ($1, $2, $3)',
250 array($id, $b, $activate[$b]));
252 db_query_params('UPDATE plugin_blocks SET status=$1
253 WHERE group_id=$2 AND name=$3',
254 array($activate[$b], $id, $b));
258 $feedback = _('Block Saved');
259 session_redirect('/plugins/blocks/?id='.$id.'&type=admin&pluginname=blocks');
260 } elseif ($type == 'configure') {
261 blocks_Project_Header(array('title'=>_('Edit Block'), 'pagename' => $pluginname, 'sectionvals' => array(group_getname($id))));
262 // DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
264 $blocks = getAvailableBlocks($group);
265 $res = db_query_params('SELECT content FROM plugin_blocks WHERE group_id=$1 AND name=$2',
267 $body = db_result($res,0,"content");
269 print _("Edit the block as you want. If you activate the HTML editor, you will be able to use WYSIWYG formatting (bold, colors...)");
271 print '<div class="align-center">';
272 print "<p><b>$blocks[$name]</b> ($name)</p>";
273 echo $HTML->openForm(array('action' => '/plugins/blocks/', 'method' => 'post'));
274 print "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
275 print "<input type=\"hidden\" name=\"pluginname\" value=\"$pluginname\" />\n";
276 print "<input type=\"hidden\" name=\"type\" value=\"configure_post\" />\n";
277 print "<input type=\"hidden\" name=\"name\" value=\"$name\" />\n";
279 // Get default body from the templates defined in the config file.
281 $body = forge_get_config($name, 'blocks');
283 $body = forge_get_config('default', 'blocks');
285 $body = '{boxHeader}'._('Enter your text here').'{boxFooter}';
290 $params['body'] = $body;
291 $params['width'] = "800";
292 $params['height'] = "500";
293 $params['group'] = $id;
294 $params['content'] = '<textarea name="body" rows="20" cols="80">'.$body.'</textarea>';
296 if (util_is_html($body)) {
297 // If user is editing HTML, keep HTML format by saying it's html
298 $params['content'] = '<input type="hidden" name="_body_content_type" value="html" />'."\n".$params['content'];
301 plugin_hook_by_reference("text_editor", $params);
302 echo $params['content'];
304 print '<br /><input type="submit" value="'._("Save").'" />';
305 echo $HTML->closeForm();
308 print "<fieldset><legend>".
311 $parsertype = forge_get_config('parser_type', 'blocks');
312 switch ($parsertype) {
314 echo html_e('p', array(), _('You can use markdown format.'));
318 _("You can create boxes like the ones on the right site of summary page, by inserting the following sentences in the content:").
321 _(": will create the top part of the box using Hello as title.").
324 _(": will create a middle part of a box using Here as title (optional).").
327 _(": will create the end part of a box.").
328 "</li></ul><ul><li>".
330 _(": will create a header before a text.").
331 "</li><li>{boxFooter}".
332 _(": will create a footer after a text.").
334 _("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.").
338 } elseif ($type == 'configure_post') {
339 $res = db_query_params('SELECT id FROM plugin_blocks WHERE group_id=$1 AND name=$2',
340 array($id, htmlspecialchars($name)));
341 if (db_numrows($res)== 0) {
342 db_query_params('INSERT INTO plugin_blocks (group_id, name, content)
343 VALUES ($1, $2, $3)',
344 array($id, htmlspecialchars($name), $body));
346 db_query_params('UPDATE plugin_blocks SET content=$1
347 WHERE group_id=$2 AND name=$3',
348 array($body, $id, htmlspecialchars($name)));
350 $feedback = $name ._(': '). _('Block configuration saved');
351 session_redirect('/plugins/blocks/?id='.$id.'&type=admin&pluginname=blocks');
354 site_project_footer();