From 848afac803c2ee0546bead3e0179816cfbc8abb0 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Wed, 18 Nov 2009 01:58:38 +0000 Subject: [PATCH] removed: hidden variable 'old_url' in emacs template git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@527 e52654a7-88a9-db11-a3e9-0013d4bc506e --- content/Makefile.dep | 2 +- content/content.h | 1 + content/emacs.cpp | 68 ++++++++++++++++++++++++++++---------------- core/db.cpp | 33 +++++++++++++++++++++ core/db.h | 2 ++ core/misc.cpp | 10 +++++++ core/misc.h | 2 ++ 7 files changed, 93 insertions(+), 25 deletions(-) diff --git a/content/Makefile.dep b/content/Makefile.dep index 6311144..70d7dc1 100755 --- a/content/Makefile.dep +++ b/content/Makefile.dep @@ -53,7 +53,7 @@ emacs.o: ../core/group.h ../core/dircontainer.h ../core/ugcontainer.h emacs.o: ../core/data.h ../core/dirs.h ../core/users.h ../core/groups.h emacs.o: ../core/functions.h ../core/lastcontainer.h ../core/mounts.h emacs.o: ../core/mount.h ../core/notify.h -emacs.o: ../templatesnotify/templatesnotify.h ../core/mount.h +emacs.o: ../templatesnotify/templatesnotify.h ../core/mount.h ../core/misc.h last.o: content.h ../core/item.h ../templates/templates.h last.o: ../templates/patterncacher.h ../core/thread.h login.o: content.h ../core/item.h ../templates/templates.h diff --git a/content/content.h b/content/content.h index af4a0aa..5f4ba6f 100755 --- a/content/content.h +++ b/content/content.h @@ -65,6 +65,7 @@ class Content void FunThread(); void FunCreateThread(); + bool PostFunSetUrlSubject(); void PostFunLogin(); void PostFunEmacsAdd(); void PostFunEmacsEdit(bool with_url); diff --git a/content/emacs.cpp b/content/emacs.cpp index f30b00d..52c6785 100755 --- a/content/emacs.cpp +++ b/content/emacs.cpp @@ -13,6 +13,8 @@ #include "../core/db.h" #include "../core/data.h" #include "../core/notify.h" +#include "../core/misc.h" + @@ -87,43 +89,61 @@ void Content::PostFunEmacsEdit(bool with_url) } +// returning true if the 'url' has to be changed +bool Content::PostFunSetUrlSubject() +{ + bool with_url = false; + + std::string * new_url = request.PostVar("url"); + std::string * new_subject = request.PostVar("subject"); + + if( request.is_item ) + { + // editing an item + if( new_url && *new_url != request.item.url ) + with_url = true; + } + else + { + // adding a new item + with_url = true; + } + + if( new_url ) + request.item.url = *new_url; + + if( new_subject ) + request.item.subject = *new_subject; + + + if( request.item.subject.empty() ) + { + request.item.subject = request.dir_table.back()->subject; + request.item.subject += "_msg_"; + request.item.subject += ToStr(db.Size(request.dir_table.back()->id, Item::file)); + } + + // if request.item.url is empty then it will be set from request.item.subject + PrepareUrl(request.item); + +return with_url; +} + void Content::PostFunEmacs() { -bool adding = true; +bool adding = !request.is_item; - if( request.is_item ) - adding = false; - try { - // these old values are ignored (if exists) - - request.PostVar("url", request.item.url); - request.PostVar("subject", request.item.subject); - - if( request.item.subject.empty() ) - request.item.subject = request.dir_table.back()->subject; - // !! dodac skladanie tytuly z ostatniego katalogu i liczby okreslajacej ile jest elementow w srodku - // !! nie bedzie obciazany modul wyszukujacy bardzo - //////// - + bool with_url = PostFunSetUrlSubject(); request.PostVar("content", request.item.content); - bool with_url = false; - std::string * old_url = request.PostVar("old_url"); - - if( !request.is_item || (old_url && *old_url!=request.item.url) ) - with_url = true; - - PrepareUrl(request.item); - if( !CheckRebus() ) { request.status = Error::rebus_bad_answer; SetUser(request.item); - return; } diff --git a/core/db.cpp b/core/db.cpp index 7df71c4..dc37b66 100755 --- a/core/db.cpp +++ b/core/db.cpp @@ -821,6 +821,39 @@ void Db::GetItems(std::vector & item_table, long parent_id, Item::Type typ } +// how many items there are in a 'parent_id' directory +long Db::Size(long parent_id, Item::Type type) +{ + PGresult * r = 0; + int res = 0; + + try + { + AssertConnection(); + + std::ostringstream query; + query << "select count(id) from core.item where "; + + if( type != Item::none ) + query << "type='" << (int)type << "' and "; + + query << "parent_id='" << parent_id << "';"; + + r = AssertQuery( query.str() ); + AssertResultStatus(r, PGRES_TUPLES_OK); + + res = atol(AssertValue(r, 0, 0)); + } + catch(const Error &) + { + } + + ClearResult(r); + +return res; +} + + // !! ta chyba nie uzywana juz? void Db::GetItem(std::vector & item_table, long id) { diff --git a/core/db.h b/core/db.h index aea7b19..7b5b9db 100755 --- a/core/db.h +++ b/core/db.h @@ -65,6 +65,8 @@ public: void GetGroups(UGContainer & group_table); // !! nowy interfejs + long Size(long parent_id, Item::Type type = Item::none); + Error GetItem(long parent_id, const std::string & url, Item & item); Error EditDefaultItem(long id, long new_default_item); diff --git a/core/misc.cpp b/core/misc.cpp index 490056e..27a2652 100755 --- a/core/misc.cpp +++ b/core/misc.cpp @@ -308,6 +308,16 @@ return buffer; } +const char * ToStr(int value) +{ +static char buffer[100]; + + sprintf(buffer, "%d", value); + +return buffer; +} + + bool IsWhite(int s) { if( s==' ' || s=='\t' || s==13 ) diff --git a/core/misc.h b/core/misc.h index 49bba22..196fa09 100755 --- a/core/misc.h +++ b/core/misc.h @@ -43,6 +43,8 @@ bool IsWhite(int s); void TrimWhite(std::string & s); void ToSmall(std::string & s); const char * SkipWhite(const char * s); +const char * ToStr(int value); + bool ValidateEmail(const std::string & email);