[svn r13702] Add a small feature : User's FCKEditor templates (http://projects.dokeos.com/index.php?do=details&task_id=2060)

skala
Julian Prud'homme 18 years ago
parent d52c6d5169
commit 80a84c5705
  1. 15
      main/document/document.inc.php
  2. 62
      main/document/document.php
  3. BIN
      main/img/wizard_gray_small.gif
  4. 1
      main/inc/lib/database.lib.php
  5. 73
      main/inc/lib/document.lib.php
  6. 83
      main/inc/lib/fckeditor/fcktemplates.xml.php
  7. 17
      main/install/dokeos_main.sql
  8. 10
      main/install/migrate-db-1.8.4-1.8.5-pre.sql

@ -1,4 +1,4 @@
<?php // $Id: document.inc.php 13406 2007-10-07 04:18:50Z yannoo $
<?php // $Id: document.inc.php 13702 2007-11-19 10:12:38Z elixir_julian $
/*
==============================================================================
@ -193,7 +193,7 @@ function build_document_icon_tag($type,$path)
* @param int $id dbase id of the document
* @return string html img tags with hyperlinks
*/
function build_edit_icons($curdirpath,$type,$path,$visibility,$id)
function build_edit_icons($curdirpath,$type,$path,$visibility,$id,$is_template)
{
if(isset($_SESSION['_gid']))
{
@ -230,6 +230,17 @@ function build_edit_icons($curdirpath,$type,$path,$visibility,$id)
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;delete='.urlencode($path).$req_gid.'&amp;'.$sort_params.'" onclick="return confirmation(\''.basename($path).'\');"><img src="../img/delete.gif" border="0" title="'.get_lang('Delete').'" alt="" /></a>';
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;move='.urlencode($path).$req_gid.'"><img src="../img/deplacer_fichier.gif" border="0" title="'.get_lang('Move').'" alt="" /></a>';
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;'.$visibility_command.'='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/'.$visibility_icon.'.gif" border="0" title="'.get_lang('Visible').'" alt="" /></a>';
if($type == 'file' && pathinfo($path,PATHINFO_EXTENSION)=='html'){
if($is_template==0){
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;add_as_template='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/wizard_small.gif" border="0" title="'.get_lang('AddAsTemplate').'" alt="'.get_lang('AddAsTemplate').'" /></a>';
}
else{
$modify_icons .= '&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;remove_as_template='.$id.$req_gid.'&amp;'.$sort_params.'"><img src="../img/wizard_gray_small.gif" border="0" title="'.get_lang('RemoveAsTemplate').'" alt=""'.get_lang('RemoveAsTemplate').'" /></a>';
}
}
return $modify_icons;
}

@ -1,4 +1,5 @@
<?php // $Id: document.php 13387 2007-10-04 15:28:00Z sourieo $
<?php // $Id: document.php 13702 2007-11-19 10:12:38Z elixir_julian $
/*
==============================================================================
Dokeos - elearning and course management software
@ -437,6 +438,63 @@ if($is_allowed_to_edit || $group_member_with_upload_rights) // TEACHER ONLY
}
}
/*======================================
TEMPLATE ACTION
======================================*/
if(isset($_GET['add_as_template']) && !isset($_POST['create_template'])){
$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 .= '<input type="submit" name="create_template" value="'.get_lang('Ok').'" />';
$new_folder_text .= '</form>';
//show the form
Display::display_normal_message($new_folder_text,false);
}
elseif(isset($_GET['add_as_template']) && isset($_POST['create_template'])){
$document_id_for_template = intval($_GET['add_as_template']);
$title = $_POST['template_title'];
$description = $_POST['template_description'];
$course_code = api_get_course_id();
$user_id = api_get_user_id();
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);
Display::display_confirmation_message(get_lang('DocumentSetAsTemplate'));
}
if(isset($_GET['remove_as_template'])){
$document_id_for_template = intval($_GET['remove_as_template']);
$course_code = api_get_course_id();
$user_id = api_get_user_id();
DocumentManager::unset_document_as_template($document_id_for_template, $course_code, $user_id);
Display::display_confirmation_message(get_lang('DocumentUnsetAsTemplate'));
}
} // END is allowed to edit
/*
@ -551,7 +609,7 @@ if($docs_and_folders)
//admins get an edit column
if ($is_allowed_to_edit || $group_member_with_upload_rights)
{
$edit_icons = build_edit_icons($curdirpath,$id['filetype'],$id['path'],$id['visibility'],$key);
$edit_icons = build_edit_icons($curdirpath,$id['filetype'],$id['path'],$id['visibility'],$key, $id['is_template']);
$row[] = $edit_icons;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 940 B

@ -64,6 +64,7 @@ define('TABLE_MAIN_SESSION_COURSE_USER', 'session_rel_course_rel_user');
define('TABLE_MAIN_SHARED_SURVEY', 'shared_survey');
define('TABLE_MAIN_SHARED_SURVEY_QUESTION', 'shared_survey_question');
define('TABLE_MAIN_SHARED_SURVEY_QUESTION_OPTION', 'shared_survey_question_option');
define('TABLE_MAIN_TEMPLATES', 'templates');
//statistic database tables
define('TABLE_STATISTIC_TRACK_E_LASTACCESS', 'track_e_lastaccess');

@ -532,6 +532,26 @@ class DocumentManager
while ($row = mysql_fetch_assoc($result))
//while ($row = mysql_fetch_array($result,MYSQL_NUM))
{
if($row['filetype']=='file' && pathinfo($row['path'],PATHINFO_EXTENSION)=='html'){
//Templates management
$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
$sql_is_template = 'SELECT id FROM '.$table_template.'
WHERE course_code="'.$_course['id'].'"
AND user_id="'.api_get_user_id().'"
AND ref_doc="'.$row['id'].'"
';
$template_result = api_sql_query($sql_is_template);
if(mysql_numrows($template_result)>0){
$row['is_template'] = 1;
}
else{
$row['is_template'] = 0;
}
}
$document_data[$row['id']] = $row;
//$document_data[] = $row;
}
@ -779,6 +799,59 @@ class DocumentManager
return false;
}
}
/**
* Allow to set a specific document as a new template for FCKEditor for a particular user in a particular course
*
* @param string $title
* @param string $description
* @param int $document_id_for_template the document id
* @param string $couse_code
* @param int $user_id
*/
function set_document_as_template($title, $description, $document_id_for_template, $couse_code, $user_id){
$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.'")';
api_sql_query($sql);
}
/**
* Unset a document as template
*
* @param int $document_id
* @param string $couse_code
* @param int $user_id
*/
function unset_document_as_template($document_id, $couse_code, $user_id){
$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
$sql = 'SELECT id FROM '.$table_template.' WHERE course_code="'.$couse_code.'" AND user_id="'.$user_id.'" AND ref_doc="'.$document_id.'"';
$result = api_sql_query($sql);
$template_id = mysql_result($result,0,0);
include_once(api_get_path(LIBRARY_PATH) . 'fileManage.lib.php');
my_delete(api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$template_id.'.jpg');
$sql = 'DELETE FROM '.$table_template.' WHERE course_code="'.$couse_code.'" AND user_id="'.$user_id.'" AND ref_doc="'.$document_id.'"';
api_sql_query($sql);
}
}
//end class DocumentManager

@ -10,12 +10,63 @@ function loadCSS($css_name){
return $template_css;
}
$css = loadCSS(api_get_setting('stylesheets'));
//<Templates imagesBasePath="fck_template/images/">
?>
<Templates imagesBasePath="fck_template/images/">
<Templates imagesBasePath="">
<?php
//Get all personnal templates in the database
$table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
$sql = 'SELECT id, title, description, ref_doc FROM '.$table_template.' WHERE course_code="'.api_get_course_id().'" AND user_id="'.api_get_user_id().'"';
$result_template = api_sql_query($sql);
while($a_template = mysql_fetch_array($result_template)){
$document_id = $a_template['ref_doc'];
$course = api_get_course_info();
$table_document = Database::get_course_table(TABLE_DOCUMENT, $_course['dbName']);
$sql_document_path = 'SELECT path FROM '.$table_document.' WHERE id="'.$document_id.'"';
$result_document_path = api_sql_query($sql_document_path);
$document_path = mysql_result($result_document_path,0,0);
$width = 100;
$height = 90;
$im = @ImageCreate($width, $height);
$bg_color = ImageColorAllocate($im, 255, 255, 255);
$ttfont = "/usr/share/fonts/truetype/freefont/FreeSans.ttf";
$text_color = ImageColorAllocate($im, 0, 0, 0);
$a_text=explode(' ',$a_template['title']);
$y=25;
foreach ($a_text as $a_part_of_title) {
imagettftext($im, 10, 0, 10, $y, $text_color, $ttfont, $a_part_of_title);
$y+=20;
}
imagejpeg($im, api_get_path(SYS_CODE_PATH).'upload/template_thumbnails/'.$a_template['id'].'.jpg');
echo '<Template title="'.htmlentities($a_template['title']).'" image="'.api_get_path(WEB_CODE_PATH).'upload/template_thumbnails/'.$a_template['id'].'.jpg">';
echo '<Description>'.htmlentities($a_template['description']).'</Description>';
echo '<Html>';
echo htmlentities(file_get_contents(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$document_path));
echo '</Html>';
echo '</Template>';
}
?>
<Template title="Text page" image="Text.png">
<Template title="Text page" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Text.png';?>">
<Description>Theory, content section, chapter...</Description>
<Html>
<![CDATA[
@ -55,7 +106,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Teacher explaining" image="Teacher_explaining.png">
<Template title="Teacher explaining" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Teacher_explaining.png';?>">
<Description>Mr Dokeos points to your content</Description>
<Html>
<![CDATA[
@ -103,7 +154,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Comparison" image="Comparison.png">
<Template title="Comparison" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Comparison.png';?>">
<Description>2 columns text page</Description>
<Html>
<![CDATA[
@ -165,7 +216,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Diagram explained" image="Diagram_explained.png">
<Template title="Diagram explained" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Diagram_explained.png';?>">
<Description>Image on the left, comment on the right</Description>
<Html>
<![CDATA[
@ -217,7 +268,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Image alone" image="Picture.png">
<Template title="Image alone" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Picture.png';?>">
<Description>Self-explaining diagram</Description>
<Html>
<![CDATA[
@ -254,7 +305,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Flash animation" image="Flash_animation_page.png">
<Template title="Flash animation" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Flash_animation_page.png';?>">
<Description>Animation + introduction text</Description>
<Html>
<![CDATA[
@ -295,7 +346,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Audio page" image="Audio_page.png">
<Template title="Audio page" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Audio_page.png';?>">
<Description>Audio + image + text : listening comprehension etc.</Description>
<Html>
<![CDATA[
@ -368,7 +419,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Video page" image="Video.png">
<Template title="Video page" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Video.png';?>">
<Description>On demand video + text</Description>
<Html>
<![CDATA[
@ -449,7 +500,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="table page" image="Table.png">
<Template title="table page" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Table.png';?>">
<Description>Spreadsheet-like page</Description>
<Html>
<![CDATA[
@ -606,7 +657,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Course preface" image="Course_preface.png">
<Template title="Course preface" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Course_preface.png';?>">
<Description>First page of a learning path</Description>
<Html>
<![CDATA[
@ -654,7 +705,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
<Template title="Assignment description" image="Assignment_description.png">
<Template title="Assignment description" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Assignment_description.png';?>">
<Description>Explain goals, roles, agenda</Description>
<Html>
<![CDATA[
@ -739,7 +790,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Resources" image="Resources.png">
<Template title="Resources" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Resources.png';?>">
<Description>Books, links, tools</Description>
<Html>
<![CDATA[
@ -815,7 +866,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Frequently asked questions" image="Frequently_asked_questions.png">
<Template title="Frequently asked questions" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Frequently_asked_questions.png';?>">
<Description>List of questions and answers </Description>
<Html>
<![CDATA[
@ -871,7 +922,7 @@ $css = loadCSS(api_get_setting('stylesheets'));
</Template>
<Template title="Certificate of completion" image="Certificate_of_completion.png">
<Template title="Certificate of completion" image="<?php echo api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/dialog/fck_template/images/Certificate_of_completion.png';?>">
<Description>To appear at the end of a learning path</Description>
<Html>
<![CDATA[

@ -778,3 +778,20 @@ CREATE TABLE `shared_survey_question_option` (
`sort` int(11) NOT NULL default '0',
PRIMARY KEY (`question_option_id`)
);
-- --------------------------------------------------------
--
-- Table structure for `templates` (User's FCKEditor templates)
--
CREATE TABLE `templates` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(100) NOT NULL,
`description` varchar(250) NOT NULL,
`course_code` varchar(40) NOT NULL,
`user_id` int(11) NOT NULL,
`ref_doc` int(11) NOT NULL,
PRIMARY KEY (`id`)
);

@ -21,6 +21,16 @@ INSERT INTO settings_current (variable, subkey, type, category, selected_value,
INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext) VALUES ('extendedprofile_registrationrequired', 'myteach', 'checkbox', 'false', 'true', 'ExtendedProfileRegistrationRequiredTitle', ExtendedProfileRegistrationRequiredComment', NULL, 'MyTeach');
INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext) VALUES ('extendedprofile_registrationrequired', 'mypersonalopenarea', 'checkbox', 'User', 'false', 'ExtendedProfileRegistrationRequiredTitle', ExtendedProfileRegistrationRequiredComment', NULL, 'MyPersonalOpenArea');
CREATE TABLE `templates` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(100) NOT NULL,
`description` varchar(250) NOT NULL,
`course_code` varchar(40) NOT NULL,
`user_id` int(11) NOT NULL,
`ref_doc` int(11) NOT NULL,
PRIMARY KEY (`id`)
);
-- xxSTATSxx
ALTER TABLE `track_e_downloads` ADD INDEX ( `down_user_id` );
ALTER TABLE `track_e_downloads` ADD INDEX ( `down_cours_id` );

Loading…
Cancel
Save