4 * Copyright (C) 2006 Alain Peyrat, Alcatel-Lucent
5 * Copyright (C) 2010 Alain Peyrat <aljeux@free.fr>
7 * This file is part of FusionForge.
9 * FusionForge is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
14 * FusionForge is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 * Standard Alcatel-Lucent disclaimer for contributing to open source
27 * "The provided file ("Contribution") has not been tested and/or
28 * validated for release as or in products, combinations with products or
29 * other commercial use. Any use of the Contribution is entirely made at
30 * the user's own responsibility and the user can not rely on any features,
31 * functionalities or performances Alcatel-Lucent has attributed to the
34 * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
35 * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
37 * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
38 * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
39 * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
40 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
41 * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
42 * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
46 require_once dirname(__FILE__)."/../../env.inc.php";
47 require_once $gfcommon.'include/pre.php';
48 require_once $gfconfig.'plugins/blocks/config.php' ;
50 require_once $gfcommon.'forum/ForumFactory.class.php';
51 require_once $gfcommon.'tracker/ArtifactFactory.class.php';
52 require_once $gfcommon.'mail/MailingListFactory.class.php';
53 require_once $gfcommon.'pm/ProjectGroupFactory.class.php';
54 require_once $gfcommon.'survey/SurveyFactory.class.php';
56 function getAvailableBlocks($group) {
58 'summary_description' =>
59 _("Block to replace the default project description with an enhanced one."),
60 // To be reworked to play nice with the widgets page.
62 // _("Block in the summary page (right)"),
64 _("Block to list informations requested to ask to join a project"),
67 if ($group->usesForum()) {
68 // Get the blocks in the forums.
69 $blocks['forum index'] = _("Display block at the top of the listing");
70 $ff = new ForumFactory($group);
71 foreach ( $ff->getForums() as $f) {
72 $blocks['forum_'.$f->getName()] = _("Display block at the top");
76 if ($group->usesTracker()) {
77 // Get the blocks in the trackers.
78 $blocks['tracker index'] = _("Display block at the top of the listing");
79 $ff = new ArtifactTypeFactory($group);
80 foreach ( $ff->getArtifactTypes() as $f) {
81 $blocks['tracker_'.$f->getName()] = _("Display block at the top");
85 if ($group->usesMail()) {
86 // Get the blocks in the mailing lists.
87 $blocks['mail index'] = _("Display block at the top of the listing");
88 $ff = new MailingListFactory($group);
89 foreach ( $ff->getMailingLists() as $f) {
90 $blocks['mail_'.$f->getName()] = _("Display block at the top");
94 if ($group->usesPM()) {
95 // Get the blocks in the tasks.
96 $blocks['tasks index'] = _("Display block at the top of the listing");
97 $ff = new ProjectGroupFactory($group);
98 foreach ( $ff->getProjectGroups() as $f) {
99 $blocks['tasks_'.$f->getName()] = _("Display block at the top");
103 if ($group->usesDocman()) {
104 // Get the blocks in the doc.
105 $blocks['doc index'] = _("Display block at the top of the listing");
106 $blocks['doc help'] = _("Display block at the top of the main page");
109 if ($group->usesSurvey()) {
110 // Get the blocks in the survey.
111 $blocks['survey index'] = _("Display block at the top of the listing");
112 $ff = new SurveyFactory($group);
113 foreach ( $ff->getSurveys() as $f) {
114 $blocks['survey_'.$f->getTitle()] = _("Display block at the top");
118 if ($group->usesNews()) {
119 // Get the blocks in the news.
120 $blocks['news index'] = _("Display block at the top of the listing");
123 if ($group->usesSCM()) {
124 // Get the blocks in the scm.
125 $blocks['scm index'] = _("Display block at the top of the listing");
128 if ($group->usesFRS()) {
129 // Get the blocks in the files.
130 $blocks['files index'] = _("Display block at the top of the listing");
136 // the header that displays for the user portion of the plugin
137 function blocks_Project_Header($params) {
138 global $DOCUMENT_ROOT,$HTML,$id;
139 $params['toptab']='blocks';
140 $params['group']=$id;
142 Show horizontal links
144 site_project_header($params);
147 $user = session_get_user(); // get the session user
149 if (!$user || !is_object($user) ) {
150 exit_error(_('Invalid User'),'home');
151 } else if ( $user->isError() ) {
152 exit_error($user->getErrorMessage(),'home');
153 } else if ( !$user->isActive()) {
154 exit_error(_('Invalid User : Not active'),'home');
158 $type = getStringFromRequest('type');
159 $id = getStringFromRequest('id');
160 $pluginname = getStringFromRequest('pluginname');
161 $name = getStringFromRequest('name');
162 $body = getHtmlTextFromRequest('body');
163 $activate = getArrayFromRequest('activate');
165 $blocks_text = array(
166 'forum' => _('Forums'),
167 'tracker' => _('Trackers'),
168 'mail' => _('Lists'),
169 'tasks' => _('Tasks'),
171 'survey' => _('Surveys'),
174 'files' => _('Files')
178 exit_error(_('Cannot Process your request : No TYPE specified'),'home'); // you can create items in Base.tab and customize this messages
180 exit_error(_('Cannot Process your request : No ID specified'),'home');
182 if ($type == 'group') {
183 $group = group_get_object($id);
187 if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the blocks plugin active
188 exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
191 session_require_perm ('project_admin', $id) ;
193 blocks_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
194 // DO THE STUFF FOR THE PROJECT PART HERE
195 echo "We are in the Project blocks plugin <br />";
196 echo "Greetings from planet " . $world; // $world comes from the config file in /etc
197 } elseif ($type == 'admin') {
198 $group = group_get_object($id);
202 if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the blocks plugin active
203 exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
205 session_require_perm ('project_admin', $id) ;
207 blocks_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
208 // DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
210 $res = db_query_params('SELECT name, status FROM plugin_blocks WHERE group_id=$1',
212 while ($row = db_fetch_array($res)) {
213 $status[ $row['name'] ] = $row['status'];
216 print _("Blocks are customizable HTML boxes in the left or right side of the pages the web site. They are created manually.");
218 print "<form action=\"/plugins/blocks/\" method=\"post\">";
219 print "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
220 print "<input type=\"hidden\" name=\"pluginname\" value=\"$pluginname\" />\n";
221 print "<input type=\"hidden\" name=\"type\" value=\"admin_post\" />\n";
223 print "<table class=\"listing\" align=\"center\">";
224 print "<thead><tr><th>".
237 $blocks = getAvailableBlocks($group);
238 foreach ($blocks as $b => $help) {
240 $class = (! isset($class) || $class == 'bgcolor-white') ? "bgcolor-grey" : "bgcolor-white";
243 if (preg_match('/(.*) index$/', $b, $match)) {
244 print '<tr><td colspan="4"><b>'.$blocks_text[$match[1]].'</b></td></tr>';
247 $checked = (isset($status[$b]) && $status[$b] == 1) ? ' checked="checked"' : '';
249 print "<tr class=\"$class\"><td>$b</td>\n" .
250 "<td align=\"center\">" .
251 "<input type=\"checkbox\" name=\"activate[$b]\" value=\"1\"$checked /></td>\n" .
253 "<td><a href=\"/plugins/blocks/index.php?id=$id&type=configure&pluginname=blocks&name=".urlencode($b)."\">configure</a></td>\n</tr>\n";
256 print "<p align=\"center\"><input type=\"submit\" value=\"" .
259 print "</form><p />";
260 } elseif ($type == 'admin_post') {
261 $group = group_get_object($id);
265 if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the blocks plugin active
266 exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
268 session_require_perm ('project_admin', $id) ;
270 $res = db_query_params('SELECT name, status FROM plugin_blocks WHERE group_id=$1',
272 while ($row = db_fetch_array($res)) {
273 $present[ $row['name'] ] = true;
274 $status[ $row['name'] ] = $row['status'];
276 $blocks = getAvailableBlocks($group);
278 // Workaround when a block has a name with a & inside.
279 // It seems sadly converted by the form (or php?).
280 foreach ($activate as $k => $v) {
281 $nk = str_replace("&","&", $k);
284 unset($activate[$k]);
288 foreach ($blocks as $b => $help) {
293 if ((!isset($status[$b]) && $activate[$b]) ||
294 (isset($status[$b]) && $activate[$b] !== $status[$b]))
296 if (!isset($present[$b])) {
297 db_query_params('INSERT INTO plugin_blocks (group_id, name, status)
298 VALUES ($1, $2, $3)',
299 array($id, $b, $activate[$b]));
301 db_query_params('UPDATE plugin_blocks SET status=$1
302 WHERE group_id=$2 AND name=$3',
303 array($activate[$b], $id, $b));
306 $msg = _('Block Saved');
307 session_redirect('/plugins/blocks/index.php?id='.$id.'&type=admin&pluginname=blocks&feedback='.urlencode($msg));
308 } elseif ($type == 'configure') {
309 $group = group_get_object($id);
313 if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the blocks plugin active
314 exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginnname),'home');
316 session_require_perm ('project_admin', $id) ;
318 blocks_Project_Header(array('title'=>$pluginname . ' Project Plugin!','pagename'=>"$pluginname",'sectionvals'=>array(group_getname($id))));
319 // DO THE STUFF FOR THE PROJECT ADMINISTRATION PART HERE
321 $blocks = getAvailableBlocks($group);
322 $res = db_query_params('SELECT content FROM plugin_blocks WHERE group_id=$1 AND name=$2',
324 $body = db_result($res,0,"content");
326 print _("Edit the block as you want. If you activate the HTML editor, you will be able to use WYSIWYG formatting (bold, colors...)");
329 print "<b>$blocks[$name]</b> ($name)";
330 print "<form action=\"/plugins/blocks/\" method=\"post\">";
331 print "<input type=\"hidden\" name=\"id\" value=\"$id\" />\n";
332 print "<input type=\"hidden\" name=\"pluginname\" value=\"$pluginname\" />\n";
333 print "<input type=\"hidden\" name=\"type\" value=\"configure_post\" />\n";
334 print "<input type=\"hidden\" name=\"name\" value=\"$name\" />\n";
336 // Get default page from the templates defined in the config file.
337 if (!$body && function_exists ('json_decode')) {
338 $templates=json_decode(file_get_contents(forge_get_config('templates_file','blocks'))) ;
339 if (isset($templates[$name])) {
340 $body = $templates[$name];
342 $body = $templates['*'];
346 $params['body'] = $body;
347 $params['width'] = "800";
348 $params['height'] = "500";
349 $params['group'] = $id;
350 $params['content'] = '<textarea name="body" rows="20" cols="80">'.$body.'</textarea>';
351 plugin_hook_by_reference("text_editor", $params);
352 echo $params['content'];
354 print "<br /><input type=\"submit\" value=\"" .
360 print "<fieldset><legend>".
363 _("<p>You can create boxes like the ones on the right site of summary page, by inserting the following sentences in the content:</p><ul><li>{boxTop Hello}: will create the top part of the box using Hello as title.</li><li>{boxMiddle Here}: will create a middle part of a box using Here as title (optional).</li><li>{boxBottom}: will create the end part of a box.</li></ul><p /><ul><li>{boxHeader}: will create a header before a text.</li><li>{boxFooter}: will create a footer after a text.</li></ul><p>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.</p>").
365 } elseif ($type == 'configure_post') {
366 $group = group_get_object($id);
370 if ( ! ($group->usesPlugin ( $pluginname )) ) {//check if the group has the blocks plugin active
371 exit_error(sprintf(_('First activate the %s plugin through the Project\'s Admin Interface'),$pluginname),'home');
373 session_require_perm ('project_admin', $id) ;
375 $res = db_query_params('SELECT id FROM plugin_blocks WHERE group_id=$1 AND name=$2',
377 if (db_numrows($res)== 0) {
378 db_query_params('INSERT INTO plugin_blocks (group_id, name, content)
379 VALUES ($1, $2, $3)',
380 array($id, $name, $body));
382 db_query_params('UPDATE plugin_blocks SET content=$1
383 WHERE group_id=$2 AND name=$3',
384 array($body, $id, $name));
386 $msg = $name .' : '. _('Block configuration saved');
387 session_redirect('/plugins/blocks/index.php?id='.$id.'&type=admin&pluginname=blocks&feedback='.urlencode($msg));
391 site_project_footer(array());