Ckecking if word are allready in lexicon

Forum_Lexicon_Desc

Ckecking if word are allready in lexicon

Beitragvon wicher » 19. Mär 2006 00:14

in admin_lexicon_edit.php i changed a bit of code so it now checks if a new word allready exists in the lexicon:

i did this, maybe there is better code, but it works for me:
Code: Alles auswählen
#
#FIND:
#
   // confirms new keyword
   case 'new_keyword_confirms':

      $admin_lexicon_action_url = append_sid("admin_lexicon_edit.$phpEx");
      ($categorie_id == 0) ? $categorie_id = 1 : '';
      $bbcode_uid = make_bbcode_uid();
      $explanation = prepare_message(trim($explanation), $html_on, $bbcode_on, $smile_on, $bbcode_uid);
      $mode = '';

      // insert new keyword in database
      $sql="INSERT INTO " . LEXICON_ENTRY_TABLE . " ( id, keyword, explanation, bbcode_uid, cat) VALUES ('', '$keyword', '$explanation', '$bbcode_uid', $categorie_id)";

      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Error update lexicon entry', '', __LINE__, __FILE__, $sql);
      }

      // Grab lexicon categories
      $sql = "SELECT cat_id, cat_titel FROM " . LEXICON_CAT_TABLE;

      if(!$result = $db->sql_query($sql))
      {
         message_die(GENERAL_ERROR, 'Could not get categories list', '', __LINE__, __FILE__, $sql);
      }
      while($row = $db->sql_fetchrow($result))
      {
         $lexicon_categories[$row['cat_id']] = $row['cat_titel'];
      }
      $db->sql_freeresult($result);

      $message = '<br />' . sprintf($lang['Keyword_caused'], $keyword, $lexicon_categories[$categorie_id]);
      $message .= '<br /><br /><meta http-equiv="refresh" content="1;url=' . $admin_lexicon_action_url . '">';
      message_die(GENERAL_MESSAGE, $message);

      break;
#
# REPLACE WITH:
#
   case 'new_keyword_confirms':
      $exist = 0;
      $keyword = strtolower($keyword);
      $sql = "SELECT keyword FROM " . LEXICON_ENTRY_TABLE;
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Kon encyclopediewoord niet checken', '', __LINE__, __FILE__, $sql);
      }
      while($row = $db->sql_fetchrow($result))
      {
         $existkeyword = $row['keyword'];
         if ($existkeyword == $keyword){$exist = 1;}
      }
      $db->sql_freeresult($result);

      if ($exist)
      {
      $message = '<br /><br />This word allready exists in the Lexicon<br />Click <a href="#" onClick="history.go(-1)">Back</a> to give your word another name or to copy your text and see if you can improve the existing word with it.<br><br>Click <a href="lexicon.php">here</a> to go to the Lexicon.';
      message_die(GENERAL_MESSAGE, $message);
      break;
      }
      else
      {
      $admin_lexicon_action_url = append_sid("lexicon_edit.$phpEx");
      ($categorie_id == 0) ? $categorie_id = 1 : '';
      $bbcode_uid = make_bbcode_uid();
      $explanation = prepare_message(trim($explanation), $html_on, $bbcode_on, $smile_on, $bbcode_uid);
      
      $poster = $userdata['username'];
      $mode = '';

      // insert new keyword in database
      $sql="INSERT INTO " . LEXICON_ENTRY_TABLE . " ( id, keyword, explanation, bbcode_uid, cat, poster) VALUES ('', '$keyword', '$explanation', '$bbcode_uid', $categorie_id, '$poster')";

      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Error update lexicon entry', '', __LINE__, __FILE__, $sql);
      }

      // Grab lexicon categories
      $sql = "SELECT cat_id, cat_titel FROM " . LEXICON_CAT_TABLE;

      if(!$result = $db->sql_query($sql))
      {
         message_die(GENERAL_ERROR, 'Could not get categories list', '', __LINE__, __FILE__, $sql);
      }
      while($row = $db->sql_fetchrow($result))
      {
         $lexicon_categories[$row['cat_id']] = $row['cat_titel'];
      }
      $db->sql_freeresult($result);


      $message = '<br />' . sprintf($lang['Keyword_caused'], $keyword, $lexicon_categories[$categorie_id]);
      $message .= '<br /><br /><meta http-equiv="refresh" content="1;url=' . $admin_lexicon_action_url . '">';
      message_die(GENERAL_MESSAGE, $message);
      break;
      }
Benutzeravatar
wicher
User
 
Beiträge: 32
Registriert: 9. Feb 2006 01:11
Wohnort: Netherlands

Beitragvon AmigaLink » 19. Mär 2006 00:47

Thank you, wicher! 8)

I will insert this code, or a something similar, in one of the next versions.
Die deutsche Sprache ist Freeware, du kannst sie benutzen, ohne dafür zu bezahlen. Sie ist aber nicht Open Source, also darfst du sie nicht verändern, wie es dir gerade passt.
Benutzeravatar
AmigaLink
Administrator
 
Beiträge: 3987
Registriert: 11. Aug 2004 01:06
Wohnort: NRW

Beitragvon wicher » 19. Mär 2006 01:31

:wink:
Benutzeravatar
wicher
User
 
Beiträge: 32
Registriert: 9. Feb 2006 01:11
Wohnort: Netherlands

Beitragvon DieterB » 19. Mär 2006 08:04

Nice,

but i get this Error-Message:

Error update lexicon entry

DEBUG MODE

SQL Error : 1054 Unknown column 'poster' in 'field list'

INSERT INTO phpbb_lexicon ( id, keyword, explanation, bbcode_uid, cat, poster) VALUES ('', '', '', '', 2, '')

Line : 142
File : admin_lexicon_edit.php

Values are my UserName, my Paasword and the Keyword and text
Gruß

DieterB
(Auch der längste Weg beginnt mit dem ersten Schritt)
DieterB
User
 
Beiträge: 41
Registriert: 26. Feb 2006 02:30
Wohnort: Hamburg

Beitragvon AmigaLink » 19. Mär 2006 08:51

Wicher hat offenbar ein zuzätzliches Tabellenfeld eingefügt.
Ersetze
Code: Alles auswählen
      $sql="INSERT INTO " . LEXICON_ENTRY_TABLE . " ( id, keyword, explanation, bbcode_uid, cat, poster) VALUES ('', '$keyword', '$explanation', '$bbcode_uid', $categorie_id, '$poster')";

gegen
Code: Alles auswählen
      $sql="INSERT INTO " . LEXICON_ENTRY_TABLE . " ( id, keyword, explanation, bbcode_uid, cat) VALUES ('', '$keyword', '$explanation', '$bbcode_uid', $categorie_id)";
Die deutsche Sprache ist Freeware, du kannst sie benutzen, ohne dafür zu bezahlen. Sie ist aber nicht Open Source, also darfst du sie nicht verändern, wie es dir gerade passt.
Benutzeravatar
AmigaLink
Administrator
 
Beiträge: 3987
Registriert: 11. Aug 2004 01:06
Wohnort: NRW

Beitragvon DieterB » 19. Mär 2006 09:46

Der nächste Fehler der mir aufgefallen ist,
habe ich ein Stichwort, z.B. "Absteifen" im Lexikon, und will ich dieses hinzufügen, wird es als "absteifen" mit übernommen.
D.h.: der erste Buchstabe wird in einen Kleinbuchstaben umgewandelt, und erst beim 2. mal, kommt die Fehlermeldung.

Und wenn man es dann editiert hat, klappt es auch.

Lösung:

case 'new_keyword_confirms':
$exist = 0;
//$keyword = strtolower($keyword); Diese Zeile wurde auskommentiert
$sql = "SELECT keyword FROM " . LEXICON_ENTRY_TABLE;
if ( !($result = $db->sql_query($sql)) )

Zugefügt nach 15 Minute(n):

Und hier einmal der (von mir) überarbeitete Code.
Folgende Änderungen habe ich vorgenommen:

1. Die Zeile
Code: Alles auswählen
//$keyword = strtolower($keyword);

wurde von mir entfernt, sie wandelte den ersten Buchstaben in einen Kleinbuchstaben um, so dass die doppelte Eingabe nicht abgefangen wurde.

2. Die URL zum Lexikon wurde von mir dahingehend angepasst,
dass sich das Lexikon (Klick auf 2. Link) in einem neuen Fenster öffnet.
In Wicher's Version kam eine Fehlermeldung, wegen fehlender oder unkorrekter Pfadzuweisung
Code: Alles auswählen
<br><br>Klicke <a href="../lexicon.php" target="Blank">hier</a> um zum Lexikon zu gelangen


3. die Fehlermeldung wurde von mir in's deutsche übersetzt.

Hier noch einmal der komplette Code.
Ersetzt einfach Wicher's Code durch meinen.
Diese version ist für deutsche User des Lexikons.

Code: Alles auswählen
// confirms new keyword
   
   case 'new_keyword_confirms':
      $exist = 0;
      $sql = "SELECT keyword FROM " . LEXICON_ENTRY_TABLE;
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Kon encyclopediewoord niet checken', '', __LINE__, __FILE__, $sql);
      }
      while($row = $db->sql_fetchrow($result))
      {
         $existkeyword = $row['keyword'];
         if ($existkeyword == $keyword){$exist = 1;}
      }
      $db->sql_freeresult($result);

      if ($exist)
      {
      $message = '<br /><br />Dieses Stichwort ist bereits in der Datenbank vorhanden. Klicke <a href="#" onClick="history.go(-1)">Neu</a> um dem Wort eine neue Bezeichnung zu geben.<br>Oder kopiere den Text, und schaue ob du ihn verbessern oder erweitern kannst.<br><br>Klicke <a href="../lexicon.php" target="Blank">hier</a> um zum Lexikon zu gelangen.';
      message_die(GENERAL_MESSAGE, $message);
      break;
      }
      else
      {
      $admin_lexicon_action_url = append_sid("lexicon_edit.$phpEx");
      ($categorie_id == 0) ? $categorie_id = 1 : '';
      $bbcode_uid = make_bbcode_uid();
      $explanation = prepare_message(trim($explanation), $html_on, $bbcode_on, $smile_on, $bbcode_uid);
       
      $poster = $userdata['username'];
      $mode = '';

           // insert new keyword in database
      $sql="INSERT INTO " . LEXICON_ENTRY_TABLE . " ( id, keyword, explanation, bbcode_uid, cat) VALUES ('', '$keyword', '$explanation', '$bbcode_uid', $categorie_id)";

      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Error update lexicon entry', '', __LINE__, __FILE__, $sql);
      }


      // Grab lexicon categories
      $sql = "SELECT cat_id, cat_titel FROM " . LEXICON_CAT_TABLE;

      if(!$result = $db->sql_query($sql))
      {
         message_die(GENERAL_ERROR, 'Could not get categories list', '', __LINE__, __FILE__, $sql);
      }
      while($row = $db->sql_fetchrow($result))
      {
         $lexicon_categories[$row['cat_id']] = $row['cat_titel'];
      }
      $db->sql_freeresult($result);


      $message = '<br />' . sprintf($lang['Keyword_caused'], $keyword, $lexicon_categories[$categorie_id]);
      $message .= '<br /><br /><meta http-equiv="refresh" content="1;url=' . $admin_lexicon_action_url . '">';
      message_die(GENERAL_MESSAGE, $message);
      break;
      }

Gruß

DieterB
(Auch der längste Weg beginnt mit dem ersten Schritt)
DieterB
User
 
Beiträge: 41
Registriert: 26. Feb 2006 02:30
Wohnort: Hamburg

Beitragvon wicher » 19. Mär 2006 12:00

Yes, i added a table field.
Sorry about not thinking about that.
And i put all lexicon words lowercase in the database because the caseunsensible fix does not work for me.
So i make sure all the words are put in in lowercase.

Thanks for changing above to correct code.
Benutzeravatar
wicher
User
 
Beiträge: 32
Registriert: 9. Feb 2006 01:11
Wohnort: Netherlands

Beitragvon DieterB » 28. Apr 2006 17:15

today, i've found 1 mistake more.

lokk at here

when i'am changing the file against the original, it's ok

but the code checked up for double-words anymore

Zugefügt nach 23 Minute(n):

i've found!!!

Code: Alles auswählen
   {
      $admin_lexicon_action_url = append_sid("admin_lexicon_edit.$phpEx");
      ($categorie_id == 0) ? $categorie_id = 1 : '';
      $bbcode_uid = make_bbcode_uid();
      $explanation = prepare_message(trim($explanation), $html_on, $bbcode_on, $smile_on, $bbcode_uid);


You must change in the line
Code: Alles auswählen
$admin_lexicon_action_url = append_sid("admin_lexicon_edit.$phpEx");



lexicon_edit against admin_lexicon_edit
Gruß

DieterB
(Auch der längste Weg beginnt mit dem ersten Schritt)
DieterB
User
 
Beiträge: 41
Registriert: 26. Feb 2006 02:30
Wohnort: Hamburg

Beitragvon wicher » 28. Apr 2006 21:08

I am sorry about that, i did not think about that when i copied it from my own files.
Fact is that i expanded my lexicon so that my users all can add words to it.
Therefor i duplicated some files from the admin to the root of my phpbb and renamed them to the same names without the "admin_" in front.
After that i did some further codechanges to them and now i can give certain users or all access to edit the lexicon.
I have it now in a way like you see at http://nl.wikipedia.org.
Its like an open encyclopedia where everybody can add there info into and edit the info that others made.

Zugefügt nach 19 Minute(n):

Here is better code, same usage as first post but now with corrected codes like the errors discussed above.
Also this code does not put all words in the lexicon in lowercase but does check all words in the lexicon wether they have uppercase letters or not.
Code: Alles auswählen
   case 'new_keyword_confirms':
      $exist = 0;
      $keywordcheck = strtolower($keyword);
      $sql = "SELECT keyword FROM " . LEXICON_ENTRY_TABLE;
      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Could not check Lexiconword', '', __LINE__, __FILE__, $sql);
      }
      while($row = $db->sql_fetchrow($result))
      {
         $existkeyword = strtolower($row['keyword']);
      
         if ($existkeyword == $keywordcheck){$exist = 1;}
      }
      $db->sql_freeresult($result);

      if ($exist)
      {
      $message = '<br /><br />This word allready exists in the Lexicon<br />Click <a href="#" onClick="history.go(-1)">Back</a> to give your word another name or to copy your text and see if you can improve the existing word with it.<br><br>Click <a href="lexicon.php">here</a> to go to the Lexicon.';
      message_die(GENERAL_MESSAGE, $message);
      break;
      }
      else
      {
      $admin_lexicon_action_url = append_sid("admin_lexicon_edit.$phpEx");
      ($categorie_id == 0) ? $categorie_id = 1 : '';
      $bbcode_uid = make_bbcode_uid();
      $explanation = prepare_message(trim($explanation), $html_on, $bbcode_on, $smile_on, $bbcode_uid);
       
      $poster = $userdata['username'];
      $mode = '';

      // insert new keyword in database
      $sql="INSERT INTO " . LEXICON_ENTRY_TABLE . " ( id, keyword, explanation, bbcode_uid, cat) VALUES ('', '$keyword', '$explanation', '$bbcode_uid', $categorie_id)";

      if ( !($result = $db->sql_query($sql)) )
      {
         message_die(GENERAL_ERROR, 'Error update lexicon entry', '', __LINE__, __FILE__, $sql);
      }

      // Grab lexicon categories
      $sql = "SELECT cat_id, cat_titel FROM " . LEXICON_CAT_TABLE;

      if(!$result = $db->sql_query($sql))
      {
         message_die(GENERAL_ERROR, 'Could not get categories list', '', __LINE__, __FILE__, $sql);
      }
      while($row = $db->sql_fetchrow($result))
      {
         $lexicon_categories[$row['cat_id']] = $row['cat_titel'];
      }
      $db->sql_freeresult($result);


      $message = '<br />' . sprintf($lang['Keyword_caused'], $keyword, $lexicon_categories[$categorie_id]);
      $message .= '<br /><br /><meta http-equiv="refresh" content="1;url=' . $admin_lexicon_action_url . '">';
      message_die(GENERAL_MESSAGE, $message);
      break;
      }
Benutzeravatar
wicher
User
 
Beiträge: 32
Registriert: 9. Feb 2006 01:11
Wohnort: Netherlands


Zurück zu Lexicon v2



Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 8 Gäste

cron