3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 require_once 'common/include/HTTPRequest.class.php';
23 class blocks_Widget_ProjectSummary extends Widget {
27 function blocks_Widget_ProjectSummary($owner_type, $owner_id) {
28 $request =& HTTPRequest::instance();
29 if ($owner_type == WidgetLayoutManager::OWNER_TYPE_USER) {
30 $this->widget_id = 'plugin_hudson_my_jobbuildhistory';
31 $this->group_id = $owner_id;
33 $this->widget_id = 'plugin_blocks_project_summary';
34 $this->group_id = $request->get('group_id');
36 $this->Widget($this->widget_id);
38 $this->setOwner($owner_id, $owner_type);
43 return ($this->title ? $this->title : 'Summary Page block of text');
46 function getDescription() {
47 return _("Add a free blocks on the project summary page to allow giving information.");
50 function hasPreferences() {
53 private function getPartialPreferencesForm($title, $content) {
55 $prefs .= '<tr><td>Title:</td>';
56 $prefs .= '<td><input type="text" class="textfield_medium" name="title" value="'. htmlspecialchars($title) .'" /></td></tr>';
57 $prefs .= '<tr><td>Content:</td>';
59 $params['body'] = $content;
60 $params['width'] = "500";
61 $params['height'] = "250";
62 $params['group'] = $this->group_id;
63 $params['toolbar'] = 'FusionForge-Basic';
64 $params['content'] = '<textarea name="body" rows="10" cols="55">'.$content.'</textarea>';
65 plugin_hook_by_reference("text_editor", $params);
66 $prefs .= '<td>'.$params['content'].'</td></tr>';
70 function getPreferences() {
71 return $this->getPartialPreferencesForm($this->getTitle(), $this->getContent());
73 function getInstallPreferences() {
74 return $this->getPartialPreferencesForm(_("Enter title of block"), '');
76 function updatePreferences(&$request) {
78 $vContentId = new Valid_UInt('content_id');
79 $vContentId->required();
80 if ($request->valid($vContentId)) {
81 $vTitle = new Valid_String('title');
82 if($request->valid($vTitle)) {
83 $title = htmlspecialchars($request->get('title'));
88 $vContent = new Valid_Text('body');
89 $vContent->required();
90 if($request->valid($vContent)) {
91 $content = $request->get('body');
92 if (getStringFromRequest('_body_content_type') == 'html') {
93 $content = TextSanitizer::purify($content);
95 $content = htmlspecialchars($content);
102 $sql = "UPDATE plugin_blocks SET title=$1, content=$2 WHERE group_id =$3 AND id = $4";
103 $res = db_query_params($sql,array($title,$content,$this->group_id,(int)$request->get('content_id')));
109 function loadContent($id) {
110 $group = group_get_object($this->group_id);
111 if ( $group && $group->usesPlugin ('blocks') ) {
112 $this->title = plugin_get_object('blocks')->getTitleBlock('summary_block'.$id);
113 $this->content = plugin_get_object('blocks')->getContentBlock('summary_block'.$id);
114 $this->content_id = $id;
117 function create(&$request) {
118 $title = getStringFromRequest('title');
119 $content = getStringFromRequest('body');
120 $res = db_query_params('INSERT INTO plugin_blocks (group_id, name, status, title, content)
121 VALUES ($1, $2, 1, $3, $4)',
122 array($this->owner_id, 'summary_block?', $title, $content));
123 $content_id = db_insertid($res, 'plugin_blocks', 'id');
124 $res = db_query_params('UPDATE plugin_blocks SET name=$1 WHERE id=$2',
125 array('summary_block'.$content_id, $content_id));
128 function getContent() {
129 return $this->content;
131 function destroy($id) {
132 $sql = 'DELETE FROM plugin_blocks WHERE id = $1 AND group_id = $2';
133 db_query_params($sql,array($id,$this->group_id));
135 function isUnique() {