Skip to content

Commit

Permalink
- Now the entries could be categorized.
Browse files Browse the repository at this point in the history
- Any entry could belongs to many categories
- Improved main page and add entry look.
- Added PostgreSQL7 squema (Thanks Janne Mikkonen!)
- Deleting entries also delete its attachments if any.
  • Loading branch information
willcast committed Sep 21, 2003
1 parent e457648 commit fb443f1
Show file tree
Hide file tree
Showing 18 changed files with 659 additions and 165 deletions.
15 changes: 13 additions & 2 deletions lang/en/glossary.php
Expand Up @@ -3,21 +3,31 @@

$string['addentry'] = "Add entry";
$string['allentries'] = "ALL";
$string['allcategories'] = "All Categories";
$string['allowduplicatedentries'] = "Duplicated entries allowed";
$string['alphabet'] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z";
$string['areyousuredelete'] = "Are you sure you want to delete this entry?";
$string['areyousuredelete'] = "Are you sure you want to delete it?";
$string['attachment'] = "Attachment";
$string['categoryview'] = "By Category";
$string['back'] = "Back";
$string['categories'] = "Categories";
$string['categoryview'] = "By category";
$string['category'] = "Category";
$string['categorydeleted'] = "Category deleted";
$string['concept'] = "Concept";
$string['concepts'] = "Concepts";
$string['definition'] = "Definition";
$string['definitions'] = "Definitions";
$string['deleteentry'] = "Delete entry";
$string['deletingnoneemptycategory'] = "If a non empty category is deleted, its relations with their entries will also be deleted. If you wish to delete the entries, you will have to do so manually.";
$string['displayformat'] = "Display format";
$string['displayformatdefault'] = "Simple, dictionary style";
$string['displayformat1'] = "Full without author.";
$string['displayformat2'] = "Full with author.";
$string['entries'] = "Entries";
$string['entrieswithoutcategory'] = "Entries without category";
$string['entry'] = "Entry";
$string['editentry'] = "Edit entry";
$string['editcategories'] = "Edit categories";
$string['entryalreadyexist'] = "Entry already exist.";
$string['entrydeleted'] = "Entry deleted.";
$string['entryexported'] = "Entry succesfully exported.";
Expand All @@ -27,6 +37,7 @@
$string['modulename'] = "Glossary";
$string['modulenameplural'] = "Glossaries";
$string['newglossaryentries'] = "New glossary entries:";
$string['nocategorized'] = "No categorized";
$string['noentries'] = "No entries found in this section";
$string['noentry'] = "No entry found.";
$string['searchconcept'] = "Search:";
Expand Down
13 changes: 12 additions & 1 deletion lang/es/glossary.php
Expand Up @@ -3,21 +3,31 @@

$string['addentry'] = "Agregar entrada";
$string['allentries'] = "TODAS";
$string['allcategories'] = "Todas las categorías";
$string['allowduplicatedentries'] = "Permitir entradas duplicadas";
$string['alphabet'] = "A|B|C|D|E|F|G|H|I|J|K|L|M|N|Ñ|O|P|Q|R|S|T|U|V|W|X|Y|Z";
$string['areyousuredelete'] = "¿Está seguro que desea borrar esta entrada?";
$string['areyousuredelete'] = "¿Está seguro que desea borrarla?";
$string['attachment'] = "Adjunto";
$string['back'] = "Volver";
$string['categories'] = "Categorías";
$string['categoryview'] = "Vista por Categoría";
$string['category'] = "Categoría";
$string['categorydeleted'] = "Categoría eliminada";
$string['concept'] = "Concepto";
$string['concepts'] = "Conceptos";
$string['definition'] = "Definición";
$string['definitions'] = "Definiciones";
$string['deleteentry'] = "Borrar entrada";
$string['deletingnoneemptycategory'] = "Si una categoría es eliminada por consiguiente su relación con las entradas también lo será. Si desea eliminar las entradas, tendrá que hacerlo manualmente.";
$string['displayformat'] = "Formato de muestra de entradas";
$string['displayformatdefault'] = "Simple, estilo diccionario";
$string['displayformat1'] = "Completo sin autor.";
$string['displayformat2'] = "Completo con autor.";
$string['editentry'] = "Editar entrada";
$string['editcategories'] = "Editar categorías";
$string['entries'] = "Entradas";
$string['entrieswithoutcategory'] = "Entradas sin categoría";
$string['entry'] = "Entrada";
$string['entryalreadyexist'] = "Esta entrada ya existe.";
$string['entrydeleted'] = "Entrada borrada.";
$string['entryexported'] = "Entrada exportada con éxito.";
Expand All @@ -27,6 +37,7 @@
$string['modulename'] = "Glosario";
$string['modulenameplural'] = "Glosarios";
$string['newglossaryentries'] = "Nuevas entradas en el glosario:";
$string['nocategorized'] = "Sin categoría";
$string['noentries'] = "No se encontraro entradas en esta sección";
$string['noentry'] = "No se econtró ninguna entrada.";
$string['searchconcept'] = "Buscar:";
Expand Down
16 changes: 4 additions & 12 deletions mod/glossary/db/mysql.php
Expand Up @@ -49,18 +49,10 @@ function glossary_upgrade($oldversion) {
`entryid` INT(10) UNSIGNED NOT NULL default '0',
PRIMARY KEY (`categoryid`, `entryid`)
) TYPE=MyISAM COMMENT='categories of each glossary entry'");

// creating a default category for every glossary
execute_sql("INSERT INTO `{$CFG->prefix}glossary_categories` (`glossaryid`, `name`)
SELECT `id`, '" . get_string("main","glossary") . "' FROM `{$CFG->prefix}glossary`");


// setting the default category for every entry.
execute_sql("INSERT INTO `{$CFG->prefix}glossary_entries_categories` (`categoryid`, `entryid`)
SELECT c.id, e.id
FROM `{$CFG->prefix}glossary_entries` e, `{$CFG->prefix}glossary_categories` c
WHERE e.glossaryid = c.glossaryid");

}

if ( $oldversion < 2003092100 ) {
execute_sql("ALTER TABLE `{$CFG->prefix}glossary_entries_categories` CHANGE `categoryid` `categoryid` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL ");
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/db/mysql.sql
Expand Up @@ -58,7 +58,7 @@ CREATE TABLE prefix_glossary_categories (
#

CREATE TABLE prefix_glossary_entries_categories (
categoryid int(10) unsigned NOT NULL default '1',
categoryid int(10) unsigned NOT NULL default '0',
entryid int(10) unsigned NOT NULL default '0',
PRIMARY KEY (categoryid, entryid)
) TYPE=MyISAM COMMENT='categories of each glossary entry';
Expand Down
13 changes: 13 additions & 0 deletions mod/glossary/db/postgres7.php
@@ -0,0 +1,13 @@
<?php

function glossary_upgrade($oldversion) {
/// This function does anything necessary to upgrade
/// older versions to match current functionality

global $CFG;


return true;
}

?>
79 changes: 79 additions & 0 deletions mod/glossary/db/postgres7.sql
@@ -0,0 +1,79 @@
# This file contains a complete database schema for all the
# tables used by this module, written in SQL

# It may also contain INSERT statements for particular data
# that may be used, especially new entries in the table log_display

#
# Table structure for table `glossary`
#

CREATE TABLE prefix_glossary (
id SERIAL,
course int4 NOT NULL default '0',
name varchar(255) NOT NULL default '',
studentcanpost int2 NOT NULL default '0',
allowduplicatedentries int2 NOT NULL default '0',
displayformat int2 NOT NULL default '0',
mainglossary int2 NOT NULL default '0',
showspecial int2 NOT NULL default '1',
showalphabet int2 NOT NULL default '1',
showall int2 NOT NULL default '1',
timecreated int4 NOT NULL default '0',
timemodified int4 NOT NULL default '0',
PRIMARY KEY (id)
);

#
# Table structure for table `glossary_entries`
#

CREATE TABLE prefix_glossary_entries (
id SERIAL,
glossaryid int4 NOT NULL default '0',
userid int4 NOT NULL default '0',
concept varchar(255) NOT NULL default '',
definition text NOT NULL,
format int2 NOT NULL default '0',
attachment VARCHAR(100) NOT NULL default '',
timecreated int4 NOT NULL default '0',
timemodified int4 NOT NULL default '0',
teacherentry int2 NOT NULL default '0',
PRIMARY KEY(id)
);

#
# Table structure for table `glossary_cageories`
#

CREATE TABLE prefix_glossary_categories (
id SERIAL,
glossaryid int4 NOT NULL default '0',
name varchar(255) NOT NULL default '',
PRIMARY KEY (id)
);

#
# Table structure for table `glossary_entries_category`
#

CREATE TABLE prefix_glossary_entries_categories (
categoryid int4 NOT NULL default '0',
entryid int4 NOT NULL default '0',
PRIMARY KEY (categoryid, entryid)
);

#
# Dumping data for table `log_display`
#

INSERT INTO prefix_log_display VALUES ('glossary', 'add', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'update', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'view', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'view all', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'add entry', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'update entry', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'add category', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'update category', 'glossary', 'name');
INSERT INTO prefix_log_display VALUES ('glossary', 'delete category', 'glossary', 'name');

2 changes: 2 additions & 0 deletions mod/glossary/deleteentry.html
Expand Up @@ -4,6 +4,8 @@
<input type="hidden" name=mode value="delete">
<input type="hidden" name=go value="1">
<input type="hidden" name=entry value="<?php echo $entry ?>">
<input type="hidden" name=currentview value="<?=$currentview ?>">
<input type="hidden" name=cat value="<?=$cat ?>">

<input type="submit" value=" <?php print_string("yes")?> ">
<input type=button value=" <?php print_string("no")?> " onclick="javascript:history.go(-1);">
Expand Down
28 changes: 21 additions & 7 deletions mod/glossary/deleteentry.php
Expand Up @@ -50,24 +50,38 @@
if ( isteacher($cm->id) or $glossary->studentcanpost ) {
if ($go) { // the operation was confirmed.
if ( $mode == "delete") {
glossary_delete_old_attachments($entry);
delete_records("glossary_entries","id", $entry);
print_simple_box_start("center","40%", "#FFBBBB");
echo "<center>$entrydeleted"; //CAMBIAR
echo "</center>";
print_simple_box_end();
} elseif ($mode == "edit") {
}
print_footer($course);
add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id", $entry);
redirect("view.php?id=$cm->id");
add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&currentview=$currentview&cat=$cat", $entry);
redirect("view.php?id=$cm->id&currentview=$currentview&cat=$cat");
} else { // the operation has not been confirmed yet so ask the user to do so
if ( $mode == "delete") {
print_simple_box_start("center","40%", "#FFBBBB");
echo "<center><b>$entryfields->concept</b><br>$strareyousuredelete"; //CAMBIAR
include("deleteentry.html");
echo "</center>";
echo "<center><b>$entryfields->concept</b><br>$strareyousuredelete";

?>
<form name="form" method="post" action="deleteentry.php">

<input type="hidden" name=id value="<?php p($cm->id) ?>">
<input type="hidden" name=mode value="delete">
<input type="hidden" name=go value="1">
<input type="hidden" name=entry value="<?php p($entry) ?>">
<input type="hidden" name=currentview value=<? p($currentview) ?>>
<input type="hidden" name=cat=<? p($cat) ?>>

<input type="submit" value=" <?php print_string("yes")?> ">
<input type=button value=" <?php print_string("no")?> " onclick="javascript:history.go(-1);">

</form>
</center>
<?
print_simple_box_end();
} elseif ($mode == "edit") {
}
}
} else {
Expand Down
35 changes: 32 additions & 3 deletions mod/glossary/edit.html
Expand Up @@ -10,6 +10,31 @@
<INPUT type="text" name="concept" size=30 value="<? p($form->concept) ?>">
</td>
</tr>
<tr valign=top>
<td align=right><p><b><?php echo get_string("categories","glossary") ?>:</b></p></td>
<td>
<?
$categories = get_records("glossary_categories","glossaryid",$glossary->id);
echo "<select size=\"";
if ( count($categories) > 7 ) {
echo 7;
}else {
echo count($categories);
}
echo "\" name=\"categories[]\" multiple=\"yes\">";

foreach ( $categories as $category ) {
echo " <option ";

if ( record_exists("glossary_entries_categories","entryid",$entry->id,"categoryid",$category->id) ) {
echo "selected " ;
}
echo "value=\"$category->id\">$category->name</option>\n";
}
?>
</select>
</td>
</tr>
<tr valign=top>
<td align=right><p><b><? echo get_string("definition","glossary") ?>:</b></p>
<font size="1">
Expand Down Expand Up @@ -37,9 +62,6 @@
$form->format = $defaultformat;
}
choose_from_menu(format_text_menu(), "format", $entry->format, "");
if ($entry->id) {
echo "<input type=\"hidden\" name=entry value=\"$entry->id\">";
}
echo "</p>";
?>
</td>
Expand All @@ -58,7 +80,14 @@
<tr>
<td colspan=2>
<p align=center>
<? if ($entry->id) {
echo "<input type=\"hidden\" name=entry value=\"$entry->id\">";
}
?>
<input type="hidden" name=id value="<?=$cm->id ?>">
<input type="hidden" name=currentview value="<?=$currentview ?>">
<input type="hidden" name=cat value="<?=$cat ?>">

<input type="submit" value="<? print_string("savechanges") ?>">
<input type="reset" value="<? print_string("revert") ?>">
</P>
Expand Down
16 changes: 14 additions & 2 deletions mod/glossary/edit.php
Expand Up @@ -7,6 +7,9 @@
require_variable($id); // Course Module ID
optional_variable($e); // EntryID

optional_variable($currentview); // categories if by category?
optional_variable($cat); // CategoryID

if (! $cm = get_record("course_modules", "id", $id)) {
error("Course Module ID was incorrect");
}
Expand Down Expand Up @@ -110,14 +113,23 @@
}
set_field("glossary_entries", "attachment", $newfilename, "id", $newentry->id);

add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id", "$newentry->id");
add_to_log($course->id, "glossary", "add entry", "view.php?id=$cm->id&eid=$newentry->id&currentview=$currentview&cat=$cat", "$newentry->id");
}
} else {
error("Could not insert this glossary entry because this concept already exist.");
}
}

redirect("view.php?id=$cm->id&eid=$newentry->id");
delete_records("glossary_entries_categories","entryid",$entry);

if ( $categories ) {
$newcategory->entryid = $newentry->id;
foreach ($categories as $category) {
$newcategory->categoryid =$category;
insert_record("glossary_entries_categories",$newcategory);
}
}
redirect("view.php?id=$cm->id&eid=$newentry->id&currentview=$currentview&cat=$cat");
die;
}
}
Expand Down
30 changes: 30 additions & 0 deletions mod/glossary/editcategories.html
@@ -0,0 +1,30 @@
<?
global $CFG, $THEME;
require_once("../../config.php");

?>

<FORM name="form" method="post" <?=$onsubmit ?> action="editcategories.php">
<table class=generalbox cellpadding=5 bgcolor="<? p($THEME->cellheading)?>">
<tr valign=top>
<td align=right><p><b><?php echo get_string("name") ?>:</b></p></td>
<td>
<INPUT type="text" name="name" size=30 value="<?=$name ?>">
</td>
</tr>
<td colspan=2>
<p align=center>
<input type="hidden" name=id value="<?=$cm->id ?>">
<input type="hidden" name=action value="<?=$action?>">
<input type="hidden" name=confirm value=1>
<input type="hidden" name=cat value=<? p($cat) ?>>
<input type="submit" value="<? print_string("savechanges") ?>">
<input type="reset" value="<? print_string("back","glossary") ?>" onclick="javascript:history.go(-1);">
</P>
</td>
</tr>
</table>
</p>


</form>

0 comments on commit fb443f1

Please sign in to comment.