[svn r16064] First attempt show image forum - See FS#2839

skala
Julio Montoya 16 years ago
parent 129d0f83e9
commit 8e138d96dc
  1. 140
      main/forum/forumfunction.inc.php
  2. 22
      main/forum/index.php
  3. 1
      main/inc/lib/add_course.lib.inc.php
  4. 1
      main/install/migrate-db-1.8.5-1.8.6-pre.sql

@ -282,6 +282,33 @@ function show_add_forum_form($inputvalues=array())
$group[] =& HTML_QuickForm::createElement('radio', 'public_private_group_forum', null, get_lang('Private'), 'private');
$form->addGroup($group, 'public_private_group_forum_group', get_lang('PublicPrivateGroupForum'), ' ');
// Forum image
$form->add_progress_bar();
if( strlen($inputvalues['forum_image']) > 0)
{
$show_preview_image='<img src='.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$inputvalues['forum_image'].'>';
$div = '<div class="row">
<div class="label">'.get_lang('UpdateImage').'</div>
<div class="formw">
'.$show_preview_image.'
</div>
</div>';
$form->addElement('html', $div .'<br/>');
$form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
}
else
{
$form->addElement('file', 'picture', ($inputvalues['forum_image'] != '' ? get_lang('UpdateImage') : get_lang('AddImage')));
}
$form->addRule('picture', get_lang('OnlyImagesAllowed'), 'mimetype', array('image/gif', 'image/jpeg', 'image/png'));
// The OK button
$form->addElement('submit', 'SubmitForum', 'OK');
@ -430,6 +457,32 @@ function store_forumcategory($values)
Display :: display_confirmation_message($return_message);
}
/**
* This function delete the forum image if exists
*
* @param int forum id
* @return boolean true if success
*
* @author Julio Montoya <gugli100@gmail.com>, Dokeos
* @version february 2006, dokeos 1.8
*/
function delete_forum_image($forum_id)
{
$table_forums = Database::get_course_table(TABLE_FORUM); echo '<br>';
$sql="SELECT forum_image FROM $table_forums WHERE forum_id = '".$forum_id."' ";
$result=api_sql_query($sql,__FILE__,__LINE__);
$row=Database::fetch_array($result);
if ($row['forum_image']!='')
{
$del_file = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$row['forum_image'];
return @unlink($del_file);
}
else
{
return false;
}
}
/**
* This function stores the forum in the database. The new forum is added to the end.
*
@ -453,14 +506,74 @@ function store_forum($values)
$new_max=$row['sort_max']+1;
$session_id = isset($_SESSION['id_session']) ? $_SESSION['id_session'] : 0;
$clean_title=Security::remove_XSS(Database::escape_string(htmlspecialchars($values['forum_title'])));
$clean_title=Security::remove_XSS(Database::escape_string(htmlspecialchars($values['forum_title'])));
if (isset($values['forum_id']))
$image_moved=false;
if(!empty($_FILES['picture']['name']))
{
$upload_ok = process_uploaded_file($_FILES['picture']);
$has_attachment=true;
}
else
{
$image_moved=true;
}
// remove existing picture if asked
if ($values['remove_picture'])
{
delete_forum_image($values['forum_id']);
}
// storing an edit
$sql="UPDATE ".$table_forums." SET
if($upload_ok)
{
if ($has_attachment)
{
$courseDir = $_course['path'].'/upload/forum/images';
$sys_course_path = api_get_path(SYS_COURSE_PATH);
$updir = $sys_course_path.$courseDir;
// Try to add an extension to the file if it hasn't one
$new_file_name = add_ext_on_mime(stripslashes($_FILES['picture']['name']), $_FILES['picture']['type']);
// user's file name
$file_name =$_FILES['picture']['name'];
if (!filter_extension($new_file_name))
{
//Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
$image_moved=false;
}
else
{
$file_extension = explode('.', $_FILES['picture']['name']);
$file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
$new_file_name = uniqid('').'.'.$file_extension;
$new_path=$updir.'/'.$new_file_name;
$result= @move_uploaded_file($_FILES['picture']['tmp_name'], $new_path);
// Storing the attachments if any
if ($result)
{
$image_moved=true;
}
}
}
}
if (isset($values['forum_id']))
{
$sql_image='';
if ($image_moved)
{
$sql_image=" forum_image='".Database::escape_string($new_file_name)."', ";
delete_forum_image($values['forum_id']);
}
// storing an edit
$sql="UPDATE ".$table_forums." SET
forum_title='".$clean_title."',
".$sql_image."
forum_comment='".Database::escape_string($values['forum_comment'])."',
forum_category='".Database::escape_string($values['forum_category'])."',
allow_anonymous='".Database::escape_string($values['allow_anonymous_group']['allow_anonymous'])."',
@ -476,10 +589,17 @@ function store_forum($values)
$return_message=get_lang('ForumEdited');
}
else
{
{
$sql_image='';
if ($image_moved)
{
$sql_image="'".$new_file_name."', ";
}
$sql="INSERT INTO ".$table_forums."
(forum_title, forum_comment, forum_category, allow_anonymous, allow_edit, approval_direct_post, allow_attachments, allow_new_threads, default_view, forum_of_group, forum_group_public_private, forum_order, session_id)
VALUES ('".$clean_title."',
(forum_title, forum_image, forum_comment, forum_category, allow_anonymous, allow_edit, approval_direct_post, allow_attachments, allow_new_threads, default_view, forum_of_group, forum_group_public_private, forum_order, session_id)
VALUES ('".$clean_title."',
".$sql_image."
'".Database::escape_string($values['forum_comment'])."',
'".Database::escape_string($values['forum_category'])."',
'".Database::escape_string($values['allow_anonymous_group']['allow_anonymous'])."',
@ -497,6 +617,7 @@ function store_forum($values)
api_item_property_update($_course, TOOL_FORUM, $last_id,"ForumCategoryAdded", api_get_user_id());
$return_message=get_lang('ForumAdded');
}
return $return_message;
}
@ -2016,6 +2137,7 @@ function show_edit_post_form($current_post, $current_thread, $current_forum, $fo
$values = $form->exportValues();
}
$form->addElement('submit', 'SubmitPost', get_lang('Ok'));
global $charset;
// setting the default values for the form elements
@ -2144,11 +2266,11 @@ function display_user_image($user_id,$name)
else
{
return $link.'<img src="'.api_get_path(WEB_CODE_PATH)."img/unknown.jpg".'" alt="'.$name.'" title="'.$name.'" /></a>';
}
}
}
/**
* The thread view counter gets increased every time someone looks at the thread
*

@ -202,7 +202,7 @@ if ($_GET['action']!='add' && $_GET['action']!='edit' )
{
foreach ($forum_categories_list as $forum_category_key => $forum_category)
{
echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"5\">";
echo "\t<tr>\n\t\t<th style=\"padding-left:5px;\" align=\"left\" colspan=\"6\">";
echo '<a href="viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.prepare4display($forum_category['cat_id']).'" '.class_visible_invisible(prepare4display($forum_category['visibility'])).'>'.prepare4display($forum_category['cat_title']).'</a><br />';
if ($forum_category['cat_comment']<>'' AND trim($forum_category['cat_comment'])<>'&nbsp;')
@ -225,7 +225,8 @@ if ($_GET['action']!='add' && $_GET['action']!='edit' )
// step 4: the interim headers (for the forum)
echo "\t<tr class=\"forum_header\">\n";
echo "\t\t<td colspan='2'>".get_lang('Forum')."</td>\n";
echo "\t\t<td colspan='3'>".get_lang('Forum')."</td>\n";
echo "\t\t<td>".get_lang('Topics')."</td>\n";
echo "\t\t<td>".get_lang('Posts')."</td>\n";
echo "\t\t<td>".get_lang('LastPosts')."</td>\n";
@ -317,11 +318,23 @@ if ($_GET['action']!='add' && $_GET['action']!='edit' )
//echo '<hr>';
if ($show_forum)
{
$form_count++;
echo "\t<tr class=\"forum\">\n";
// Showing the image
echo "\t\t<td width=\"150\">";
echo '<img src="'.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$forum['forum_image'].'">';
echo "</td>\n";
echo "\t\t<td width=\"20\">";
if ($forum['forum_of_group']!=='0')
{
if (is_array($whatsnew_post_info[$forum['forum_id']]) and !empty($whatsnew_post_info[$forum['forum_id']]))
@ -334,14 +347,17 @@ if ($_GET['action']!='add' && $_GET['action']!='edit' )
}
}
else
{
{
if (is_array($whatsnew_post_info[$forum['forum_id']]) and !empty($whatsnew_post_info[$forum['forum_id']]))
{
echo icon('../img/forum.gif');
}
else
{
echo icon('../img/forum.gif');
}
}

@ -490,6 +490,7 @@ function update_Db_course($courseDbName)
forum_order int default NULL,
locked int NOT NULL default 0,
session_id int NOT NULL default 0,
forum_image varchar(255) NOT NULL default '',
PRIMARY KEY (forum_id)
) TYPE=MyISAM";

@ -45,3 +45,4 @@ UPDATE tool SET category = 'interaction' WHERE name = 'forum';
ALTER TABLE survey ADD show_form_profile int NOT NULL default 0;
ALTER TABLE survey ADD form_fields TEXT NOT NULL;
ALTER TABLE quiz_answer CHANGE hotspot_type hotspot_type ENUM( 'square', 'circle', 'poly', 'delineation' ) NULL DEFAULT NULL;
ALTER TABLE forum_forum ADD forum_image varchar(255) NOT NULL default '';

Loading…
Cancel
Save