[svn r18961] * image upload for personal template

* display image in template list
skala
Patrick Cool 16 years ago
parent 8391b4ec42
commit 90063aefe4
  1. 50
      main/document/document.php
  2. 25
      main/inc/lib/document.lib.php
  3. 39
      main/inc/lib/fckeditor/editor/dialog/fck_template.html

@ -1,4 +1,4 @@
<?php // $Id: document.php 18706 2009-02-26 15:53:50Z cfasanando $
<?php // $Id: document.php 18961 2009-03-11 14:05:12Z pcool $
/*
==============================================================================
Dokeos - elearning and course management software
@ -602,17 +602,20 @@ if($is_allowed_to_edit || $group_member_with_upload_rights) // TEACHER ONLY
$document_id_for_template = intval($_GET['add_as_template']);
//create the form that asks for the directory name
$new_folder_text = '<form name="set_document_as_new_template" action="'.api_get_self().'?add_as_template='.$document_id_for_template.'" method="post">';
$new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
$new_folder_text .= '<table><tr><td>';
$new_folder_text .= get_lang('TemplateName').' : </td>';
$new_folder_text .= '<td><input type="text" name="template_title" /></td></tr>';
$new_folder_text .= '<tr><td>'.get_lang('TemplateDescription').' : </td>';
$new_folder_text .= '<td><textarea name="template_description"></textarea></td></tr></table>';
$new_folder_text .= '<button type="submit" name="create_template">'.get_lang('Ok').'</button>';
$new_folder_text .= '</form>';
$template_text = '<form name="set_document_as_new_template" enctype="multipart/form-data" action="'.api_get_self().'?add_as_template='.$document_id_for_template.'" method="post">';
$template_text .= '<input type="hidden" name="curdirpath" value="'.$curdirpath.'" />';
$template_text .= '<table><tr><td>';
$template_text .= get_lang('TemplateName').' : </td>';
$template_text .= '<td><input type="text" name="template_title" /></td></tr>';
$template_text .= '<tr><td>'.get_lang('TemplateDescription').' : </td>';
$template_text .= '<td><textarea name="template_description"></textarea></td></tr>';
$template_text .= '<tr><td>'.get_lang('TemplateImage').' : </td>';
$template_text .= '<td><input type="file" name="template_image" id="template_image" /></td></tr>';
$template_text .= '</table>';
$template_text .= '<button type="submit" name="create_template">'.get_lang('Ok').'</button>';
$template_text .= '</form>';
//show the form
Display::display_normal_message($new_folder_text,false);
Display::display_normal_message($template_text,false);
}
elseif(isset($_GET['add_as_template']) && isset($_POST['create_template']))
{
@ -623,12 +626,33 @@ if($is_allowed_to_edit || $group_member_with_upload_rights) // TEACHER ONLY
$course_code = api_get_course_id();
$user_id = api_get_user_id();
if(!is_dir(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'))
// create the template_thumbnails folder in the upload folder (if needed)
if(!is_file(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'))
{
mkdir(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/',0777);
}
DocumentManager::set_document_as_template($title, $description, $document_id_for_template, $course_code, $user_id);
// upload the file
if (!empty($_FILES['template_image']['name']))
{
echo 'uploading';
include_once (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
$upload_ok = process_uploaded_file($_FILES['template_image']);
if ($upload_ok)
{
// Try to add an extension to the file if it hasn't one
$new_file_name = $_course['sysCode'].'-'.add_ext_on_mime(stripslashes($_FILES['template_image']['name']), $_FILES['template_image']['type']);
// upload dir
$upload_dir = api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/';
// move the uploaded file to the home folder
$result= @move_uploaded_file($_FILES['template_image']['tmp_name'], $upload_dir.$new_file_name);
}
}
DocumentManager::set_document_as_template($title, $description, $document_id_for_template, $course_code, $user_id, $new_file_name);
Display::display_confirmation_message(get_lang('DocumentSetAsTemplate'));
}

@ -988,21 +988,24 @@ class DocumentManager
* @param string $couse_code
* @param int $user_id
*/
function set_document_as_template($title, $description, $document_id_for_template, $couse_code, $user_id){
function set_document_as_template($title, $description, $document_id_for_template, $couse_code, $user_id, $image)
{
// Database table definition
$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
$title = Database::escape_string($title);
$description = Database::escape_string($description);
$document_id_for_template = Database::escape_string($document_id_for_template);
$couse_code = Database::escape_string($couse_code);
$user_id = Database::escape_string($user_id);
$sql = 'INSERT INTO '.$table_template.'(title, description, course_code, user_id, ref_doc)
VALUES ("'.$title.'", "'.$description.'", "'.$couse_code.'", "'.$user_id.'", "'.$document_id_for_template.'")';
// creating the sql statement
$sql = "INSERT INTO ".$table_template."
(title, description, course_code, user_id, ref_doc, image)
VALUES (
'".Database::escape_string($title)."',
'".Database::escape_string($description)."',
'".Database::escape_string($couse_code)."',
'".Database::escape_string($user_id)."',
'".Database::escape_string($document_id_for_template)."',
'".Database::escape_string($image)."')";
api_sql_query($sql);
return true;
}

@ -29,7 +29,7 @@
<style type="text/css">
.TplList
{
/* border: #dcdcdc 2px solid; */
border: #fff 2px solid;
background-color: #ffffff;
overflow: auto;
width: 165px;
@ -37,32 +37,26 @@
.TplItem
{
margin: 3px;
padding: 0px;
/* border: #eeeeee 0px solid; */
border: #ffffff 1px solid !important;
text-align:right;
margin: 5px;
padding: 7px;
border: #eeeeee 1px solid;
text-decoration: none;
font-weight :normal;
}
.TplItem TABLE
{
display: inline;
text-align:right;
}
.TplTitle
{
font-weight: normal;
font-weight: bold;
}
.TplTitle a
{
text-align:right;
color:000;
text-decoration: none;
font-weight :normal;
}
</style>
<script src="common/fck_dialog_common.js" type="text/javascript"></script>
@ -113,8 +107,8 @@ function LoadTemplatesXml()
oXml.LoadUrl( FCKConfig.TemplatesXmlPath ) ;
// Get the Images Base Path.
//var oAtt = oXml.SelectSingleNode( 'Templates/@imagesBasePath' ) ;
//var sImagesBasePath = oAtt ? oAtt.value : '' ;
var oAtt = oXml.SelectSingleNode( 'Templates/@imagesBasePath' ) ;
var sImagesBasePath = oAtt ? oAtt.value : '' ;
// Get the "Template" nodes defined in the XML file.
var aTplNodes = oXml.SelectNodes( 'Templates/Template' ) ;
@ -137,11 +131,11 @@ function LoadTemplatesXml()
if ( (oPart = oXml.SelectSingleNode( 'Description', oNode )) )
oTemplate.Description = oPart.text ? oPart.text : oPart.textContent ;
/*
// Get the Template Image.
if ( (oPart = oNode.attributes.getNamedItem('image')) )
oTemplate.Image = sImagesBasePath + oPart.value ;
*/
// Get the Template HTML.
if ( (oPart = oXml.SelectSingleNode( 'Html', oNode )) )
@ -173,17 +167,20 @@ function LoadTemplatesXml()
// Build the inner HTML of our new item DIV.
var sInner = '<table><tr>' ;
/*
if ( oTemplate.Image )
sInner += '<td valign="top"><img src="' + oTemplate.Image + '"><\/td>' ;
*/
sInner += '<td valign="top"><img src="' + oTemplate.Image + '"><br />' ;
else
sInner += '<td valign="top"><img src="fck_template/images/noimage.gif"><br />' ;
sInner += '<div class="TplTitle"><a href="javascript:void(0);" title="'+oTemplate.Description+'" >' + oTemplate.Title + '<\/a><\/div>';
sInner += '<td valign="top"><div class="TplTitle"><a href="javascript:void(0);" title="'+oTemplate.Description+'" >' + oTemplate.Title + '<\/a><\/div>';
/*
if ( oTemplate.Description )
sInner += '<div>' + oTemplate.Description + '<\/div>' ;
*/
sInner += '<\/td><\/tr><\/table>' ;

Loading…
Cancel
Save