FAQ - SISTEM

Publicado por Perfil removido 18/04/2005

[ Hits: 5.002 ]

Download faq-system-0.3.5.tar[1]




Este é um pacote de cgi-programas para manter um FAQ. Os dados são armazenados em um banco de dados de mysql. Características de chave incluem: fácil usar na interface web, gera o faq e veja o resultado ao mesmo tempo, vários tipos de formato formata poss

  



Esconder código-fonte

faq-system-0.3.5/                                                                                    40755     764     144            0  6727346156  12432  5                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  faq-system-0.3.5/answer.cc                                                                          100644     764     144        10075  6727307346  14356  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  #include "conf.h"

int main(void)
{
   //int i;
   char **tuple;
   Database *db;
   DBResult *res;

   db = new Database();

   cgi C;
        C.initPage();

   Pro p;

   string instance;
        instance = C.get_value("instance");
        config CONF(instance);

   const char* SCRIPTSUPPORT;
   const char* RUN;
        const char* MYDATABASE;
        const char* MYTOPIC; 
        const char* MYANSWER;
        const char* MYQUESTION;

   const char* USER;
   const char* PASS;
   const char* HOST; 
   HOST = CONF.HOST.c_str();
   USER = CONF.USER.c_str();
   PASS = CONF.PASS.c_str();

        MYDATABASE = CONF.MYDATABASE.c_str();
        MYTOPIC = CONF.MYTOPIC.c_str();
        MYANSWER = CONF.MYANSWER.c_str();  
        MYQUESTION = CONF.MYQUESTION.c_str();
   SCRIPTSUPPORT = CONF.SCRIPTSUPPORT.c_str();
   RUN = CONF.RUN.c_str();

   // Initialise the database - for future releases
   if (db->init() != DB_COMMAND_OK) {
      fprintf(stdout, "Unable to initialize database: %s\n\n", 
              db->errorMessage());
      exit(0);
        }
   // Connect to database on localhost
        if (db->connect(HOST, "", MYDATABASE, USER, PASS) != DB_CONNECTION_OK) {
        fprintf(stdout, "Unable connect to database '%s': %s\n\n",
                 MYDATABASE, db->errorMessage());
                 exit(0);
        }
   
   string stage, question_id, topic_id, keys, answer, question;
   question_id = C.get_value("question_id");
   answer = C.get_value("answer");
   keys = C.get_value("keys");
   stage = C.get_value("stage");

        topic_id = C.get_value("topic_id");
        question_id = C.get_value("question_id");

   HTML h;
        cout << h.html()
        << h.body("#ffffff") << endl;

   if( stage == "prepare")
   {
      res = db->exec("SELECT value FROM %s WHERE question_id = '%s'", MYQUESTION, question_id.c_str());
      tuple = res->getTuple();
                while (tuple != NULL)
                {
         cout << "<h2>" << *(tuple) << "</h2>\n";
         tuple = res->getTuple();
                }
                cout << "<form name=answer action=\"" << URL << "/" << ADMIN << "/answer.cgi\" method=post>" << endl
                << h.font("arial","2")
                << "Answer this question."
                << h._font() << "<br></br>" << endl
                << h.font("arial","2") << "Value:" << h._font() << "<br></br>" << endl
                << h.textarea("answer", "", "15", "80") << "<br></br>" << endl
                << h.font("arial","2") << "Keywords:" << h._font() << "<br></br>" << endl
                << h.textarea("keys", "", "4", "30") << "<br></br>" << endl
                << h.in_hidden("question_id" ,question_id) << endl
      << h.in_hidden("topic_id",topic_id) << endl
      << "<input type=hidden name=instance value=\"" << instance << "\">\n"
                << h.in_submit("Save")
                << h.in_reset("Clear") << endl
                << h._form() << endl;
   }
   else
   {
      string tmp("");
/*
      int len = answer.length();
      for(int i=0;i<len;i++)
      {
         if(answer[i] == char(39))
         {   
            tmp += "\\'";
         }
         else
            tmp += answer[i];
      }
*/
      tmp = p.parse(answer);
            
      //cout << tmp << endl;

      res = db->exec("INSERT INTO %s VALUES(0, %s, '%s', '%s')",MYANSWER, question_id.c_str(), tmp.c_str(), keys.c_str());
      if (res->status() != DB_COMMAND_OK) {
         fprintf(stdout, "Can't insert into table '%s': %s\n\n", MYANSWER, db->errorMessage());
         delete res;
         delete db;
         exit(0);
      }
      cout << "Data inserted\n";


      db->exec(res, "SELECT value FROM %s WHERE question_id = '%s'", MYQUESTION, question_id.c_str());
                tuple = res->getTuple();
                while (tuple != NULL)
                {
                        question =  *(tuple);
                        tuple = res->getTuple();
                }
   }

//   Pro p;
   cout << p.back("dbadmin", instance)
        << h._body()
        << h._html()
        << endl;    
   if((strcmp(SCRIPTSUPPORT, "on")==0) && stage != "prepare")
        {
                string b;
                b = "";
                b += topic_id + "." + question_id + ".";
                p.script("answer.cgi", question, b, instance,string(RUN));
        }  
   delete res;         // Drop buffer
   delete db;         // Close connection
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                   faq-system-0.3.5/database.cc                                                                        100644     764     144         7520  6727307346  14604  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  /*
   mysql C++ wrapper library

   Author: Roland Haenel <rh@ginster.net>

   This program is in the public domain.
   Distribute and use it freely.
*/

#include <unistd.h>
#include <stdarg.h>
#include <time.h>

#include "database.h"

Database::Database()
{
   connected = false;   // No connection yet
   strcpy(error, "No connection established");
}

Database::~Database()
{
   disconnect();      // Disconnect if connected to database
}

int Database::status()
{
   if (connected == false) return DB_CONNECTION_NONE;
   return DB_CONNECTION_OK;
}

int Database::init()
{
   return DB_COMMAND_OK;
}

char *Database::errorMessage()
{
   if (connected == false) return error;
   return mysql_error(&mysql);
}

int Database::connect(const char *host, char *port, const char *db, const char* user, const char* pass)
{
   char *unused = port;

/* ORIGINAL
   if (mysql_connect(&mysql, host, NULL, NULL) == NULL) {
      strcpy(error, "Connect to database failed");
      return DB_ERROR;
   }
*/
   if (mysql_connect(&mysql, host, user, pass) == NULL) {
                strcpy(error, "Connect to database failed");
                return DB_ERROR;
        }

   if (mysql_select_db(&mysql, db)) {
      mysql_close(&mysql);
      strcpy(error, "No such database");   
      return DB_ERROR;
   }

   unused++;         // Just to suppress a compiler warning
   connected = true;
   return DB_CONNECTION_OK;
}

void Database::disconnect()
{
   if (connected == false) return;
   mysql_close(&mysql);
   connected = false;
}

int Database::reset()
{
   return DB_COMMAND_OK;
}

DBResult *Database::exec(char *sqlFormat, ...)
{
   va_list ap;
   char sqlCommand[5000];

   va_start(ap, sqlFormat);
   vsnprintf(sqlCommand, 5000, sqlFormat, ap);
   va_end(ap);

   return new DBResult(&mysql, sqlCommand);
}

void Database::exec(DBResult *res, char *sqlFormat, ...)
{
   va_list ap;
   char sqlCommand[5000];

   va_start(ap, sqlFormat);
   vsnprintf(sqlCommand, 5000, sqlFormat, ap);
   va_end(ap);

   res->init(&mysql, sqlCommand);
}

// ------------------- Database result implementation ------------------

DBResult::DBResult()
{
   result     = NULL;
   haveError  = false;
}

DBResult::DBResult(MYSQL *mysql, char *query)
{
   result     = NULL;
   haveError  = false;
   init(mysql, query);
}

DBResult::~DBResult()
{
   if (result != NULL)         // Free memory resources
      mysql_free_result(result);
}

void DBResult::init(MYSQL *mysql, char *query)
{
   if (result != NULL) {
      mysql_free_result(result);
      result = NULL;
   }
   if (mysql_query(mysql, query) == 0) {      // query OK
      result = mysql_store_result(mysql);
      if (result == NULL) {         // empty query
         if (mysql_num_fields(mysql) == 0)
            haveError = false;
         else
            haveError = true;
      } else haveError  = false;
   } else haveError  = true;
}

int DBResult::status()
{
   if (haveError)      return DB_ERROR;
   if (result == NULL) return DB_COMMAND_OK;
   return DB_TUPLES_OK;
}

int DBResult::nrTuples()
{
   if (result == NULL) return 0;
   return mysql_num_rows(result);
}

int DBResult::nrFields()
{
   if (result == NULL) return 0;
   return mysql_num_fields(result);
}

char *DBResult::fieldName(int n)
{
   MYSQL_FIELD *field;

   if (result == NULL) return NULL;
   mysql_field_seek(result, n);
   field = mysql_fetch_field(result);
   if (field == NULL) return NULL;
   return field->name;
}

int DBResult::fieldSize(int n)
{
   MYSQL_FIELD *field;

   if (result == NULL) return 0;
   mysql_field_seek(result, n);
   field = mysql_fetch_field(result);
   if (field == NULL) return 0;
   return field->length;
}

int DBResult::fieldSize(char *name)
{
   int i;

   if (result == NULL) return 0;
   for (i = 0; i < nrFields(); i++)
      if (!strcmp(name, fieldName(i)))
         return fieldSize(i);
   return 0;
}

void DBResult::seekTuple(int tuple)
{
   if (result == NULL) return;
   mysql_data_seek(result, tuple);
}

char **DBResult::getTuple()
{
   MYSQL_ROW row;

   if (result == NULL) return NULL;
   row = mysql_fetch_row(result);
   return row;
}

char **DBResult::getTuple(int tuple)
{
   seekTuple(tuple);
   return getTuple();
}
                                                                                                                                                                                faq-system-0.3.5/delete.cc                                                                          100644     764     144        14467  6727307346  14332  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  #include "conf.h"

int main(void)
{
        //int i;
        char **tuple;
        Database *db;
        DBResult *res;

        db = new Database();

   cgi C;
        C.initPage();

   string instance;
        instance = C.get_value("instance");
        config CONF(instance);

   const char* MYDATABASE;
        const char* MYTOPIC;
        const char* MYANSWER;
        const char* MYQUESTION;
        const char* USER;
        const char* PASS;
        const char* HOST;
        HOST = CONF.HOST.c_str();
        USER = CONF.USER.c_str();
        PASS = CONF.PASS.c_str(); 
        MYDATABASE = CONF.MYDATABASE.c_str();
        MYTOPIC = CONF.MYTOPIC.c_str();
        MYANSWER = CONF.MYANSWER.c_str();
        MYQUESTION = CONF.MYQUESTION.c_str();

        string warn, stage, mode, answer, topic, question, question_id, answer_id, topic_id, keys;
   string TABLE, hidden_mode, hidden_id, id, action, value;
   
   if (db->init() != DB_COMMAND_OK) {
                fprintf(stdout, "Unable to initialize database: %s\n\n",
                        db->errorMessage());
                exit(0);
        }

        // Connect to database on localhost
   if (db->connect(HOST, "", MYDATABASE, USER, PASS) != DB_CONNECTION_OK) { 
                fprintf(stdout, "Unable connect to database '%s': %s\n\n",
                        MYDATABASE, db->errorMessage());
                exit(0);
        } 

   stage = C.get_value("stage");
   mode = C.get_value("mode");

   HTML h;
   
   cout << h.html() << h.body("#ffffff") << endl;

      if (mode == "topic")
      {
         topic_id = C.get_value("topic_id");
         hidden_id = topic_id;
         TABLE = MYTOPIC;
         warn = "Warning! You are about to delete a TOPIC! Every related question and it's ";
         warn += "related answers will deleted too!<br><br>";   
      }
      else if (mode == "question")
      {
         question_id = C.get_value("question_id");
         hidden_id = question_id;
         TABLE = MYQUESTION;
         warn = "Warning! You are about to delete a QUESTION! Every related answer will";
         warn += " deleted too!<br><br>";
      }
      else if (mode == "answer")
      {
         answer_id = C.get_value("answer_id");
         hidden_id = answer_id;
         TABLE = MYANSWER;
         warn = "Warning! You are about to delete an ANSWER!<br><br>";
      }
      warn += "<b>Are you sure?</b>\n";
      id = mode + "_id";

   if (stage == "prepare")
   {
      res = db->exec("SELECT value FROM %s WHERE %s = %s", TABLE.c_str(), id.c_str(), hidden_id.c_str());
                tuple = res->getTuple();
                while (tuple != NULL)
                {
                        value = *(tuple);
         tuple = res->getTuple();
                }


                cout << "<form name=modify action=\"" << URL << "/" << ADMIN << "/delete.cgi\" method=post>" << endl
                << "<h2>DELETE " << mode << ": \"" << value << "\"</h2>\n"
                << h.font("arial","2") << "<br></br>" << endl
                << warn << "<br></br>" <<  h._font() << endl;
                
      cout << h.in_hidden(id, hidden_id) << endl
      << h.in_hidden("mode", mode) << endl
      << h.in_hidden("stage", "delete") << endl
                << h.in_submit("  DELETE  ")
      << h.in_hidden("instance",instance)
                << h._form() << endl; 
   }
   else
   {
      int question_max;
      string *qid;
      if(mode == "topic")
      {
         // find out question_max
                   res = db->exec("SELECT question_id FROM %s WHERE topic_id = %s", MYQUESTION, hidden_id.c_str());
                   tuple = res->getTuple();
                   question_max = 0;
                   while (tuple != NULL)
                   {
                           question_max++;
                           tuple = res->getTuple();
                   }
         
         qid = new string[question_max];
         int a = 0;
         res = db->exec("SELECT question_id FROM %s WHERE topic_id = %s", MYQUESTION, hidden_id.c_str());
                        tuple = res->getTuple();
         while (tuple != NULL)
         {
            qid[a] = *(tuple);
            a++;
            tuple = res->getTuple();
         }
         
         // Delete all answers:
         for(int m=0; m<question_max; m++)
         {
            db->exec(res, "DELETE from %s WHERE question_id = %s", MYANSWER, qid[m].c_str());
            if (res->status() != DB_COMMAND_OK) {
               fprintf(stdout, "Can't delete answer number: %s. \n %s \n\n", qid[m].c_str(), db->errorMessage());
               delete res;
               delete db;
               exit(0);
            }    
         }      

         // Delete all questions:
         db->exec(res, "DELETE from %s WHERE topic_id = %s", MYQUESTION, hidden_id.c_str());
         if (res->status() != DB_COMMAND_OK) {
            fprintf(stdout, "Can't delete question. %s \n\n", db->errorMessage());
            delete res;
            delete db;
            exit(0);
         }
         
         // Delete the topic:
         db->exec(res, "DELETE from %s WHERE topic_id = %s", MYTOPIC, hidden_id.c_str());
                        if (res->status() != DB_COMMAND_OK) {
                                fprintf(stdout, "Can't delete question. %s \n\n", db->errorMessage());
                                delete res;
                                delete db;
                                exit(0);
                        }
      }
      else if(mode == "question")
      {
         // Delete all answers:
         res = db->exec("DELETE from %s WHERE question_id = %s", MYANSWER, hidden_id.c_str());
         if (res->status() != DB_COMMAND_OK) {
            fprintf(stdout, "Can't delete answer number: %s. \n %s \n\n", hidden_id.c_str(), db->errorMessage());
            delete res;
            delete db;
            exit(0);
         }
         
         //Delete question:
         db->exec(res, "DELETE from %s WHERE question_id = %s", MYQUESTION, hidden_id.c_str());
                        if (res->status() != DB_COMMAND_OK) {
                                fprintf(stdout, "Can't delete question. %s \n\n", db->errorMessage());
                                delete res;
                                delete db;
                                exit(0);
                        }
      }
      else if(mode == "answer")
      {
         // Delete all answers:
                        res = db->exec("DELETE from %s WHERE answer_id = %s", MYANSWER, hidden_id.c_str());
                        if (res->status() != DB_COMMAND_OK) {
                                fprintf(stdout, "Can't delete answer. \n %s \n\n", db->errorMessage());
                                delete res;
                                delete db;
                                exit(0);
                        }
      
      }
      cout << h.font("arial", "2")
      << mode << " deleted.<br><br>\n";
   }
   Pro p; 
   cout << p.back("dbadmin", instance) << endl;
   cout << h._body() << h._html() << endl;

}
                                                                                                                                                                                                         faq-system-0.3.5/getanswer.cc                                                                       100644     764     144         6374  6727307346  15045  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  #include "conf.h"

int main(void)
{
        //int i;
        char **tuple;
        Database *db;
        DBResult *res;

        db = new Database();

   cgi C;
        C.initPage();

   string instance;
        instance = C.get_value("instance");
        config CONF(instance);

   const char* MYDATABASE;
        const char* MYTOPIC;
        const char* MYANSWER;
        const char* MYQUESTION;
   const char* HOST;
        const char* USER;
        const char* PASS;
        HOST = CONF.HOST.c_str();
   USER = CONF.USER.c_str();
        PASS = CONF.PASS.c_str(); 
        MYDATABASE = CONF.MYDATABASE.c_str();
        MYTOPIC = CONF.MYTOPIC.c_str();
        MYANSWER = CONF.MYANSWER.c_str();
        MYQUESTION = CONF.MYQUESTION.c_str();

        // Initialise the database - for future releases
        if (db->init() != DB_COMMAND_OK) {
                fprintf(stdout, "Unable to initialize database: %s\n\n",
                        db->errorMessage());
                exit(0);
        }

        string stage, question, answer_id, question_id, topic_id, keys;
   string answer[10];
        int i, u;
   question_id = C.get_value("question_id");
   stage = C.get_value("stage");


   HTML h;
   
   cout << h.html() << h.body("#ffffff") << endl;


        if (db->init() != DB_COMMAND_OK) {
                fprintf(stdout, "Unable to initialize database: %s\n\n",
                        db->errorMessage());
                exit(0);
        }

                        // Connect to database on localhost
   if (db->connect(HOST, "", MYDATABASE, USER, PASS) != DB_CONNECTION_OK) { 
                fprintf(stdout, "Unable connect to database '%s': %s\n\n",
                        MYDATABASE, db->errorMessage());
                exit(0);
        } 

   res = db->exec("SELECT value FROM %s WHERE question_id = %s", MYQUESTION, question_id.c_str());
   tuple = res->getTuple();
   while (tuple != NULL)
        {
      cout << "<h1>" << *(tuple) << "</h1>" << endl;
                tuple = res->getTuple();
        } 

   db->exec(res, "SELECT value FROM %s WHERE question_id = %s", MYANSWER, question_id.c_str());
   tuple = res->getTuple();
   i=0;
   while (tuple != NULL)
        {
      answer[i] = *(tuple);
                tuple = res->getTuple();
                i++; 
        }

          if (stage == "dbadmin")
          {
      u=0;
                  db->exec(res, "SELECT answer_id FROM %s WHERE question_id = %s", MYANSWER, question_id.c_str());
                  tuple = res->getTuple();
                  while (tuple != NULL)
                  {
                          cout << "<p><A HREF=\"" << URL << "/" << ADMIN ;
                          cout << "/modify.cgi?instance=" << instance << "&stage=prepare&mode=answer&answer_id=" << *(tuple) ;
                          cout << "\">[ modify ]</A> "; 
         cout << "<A HREF=\"" << URL << "/" << ADMIN << "/delete.cgi?instance=" << instance
                   << "&stage=prepare&mode=answer&answer_id=" << *(tuple) << "\">[ delete ]</A><br><br>\n"
         << answer[u++] << "</p><br>";
         tuple = res->getTuple();
                  }
      
          } 
   else
   {
      for(u=0;u<i;u++)
      {
         cout << "<p>\n";
         cout << answer[u];
         cout << "</p>\n";
      }
    }
   Pro p; 
   if(stage == "dbadmin")
      cout << p.back("dbadmin", instance) << endl;
   else
      cout << p.back("user", instance) << endl;
   cout << h._body() << h._html() << endl;

}
                                                                                                                                                                                                                                                                    faq-system-0.3.5/index.cc                                                                           100644     764     144        41410  6727340400  14147  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  #include "conf.h"
#include <fstream.h>
int main(void)
{
   int i;
   char **tuple;
   Database *db;
   DBResult *res;
   HTML h;
   cgi C;
   C.initPage();
   string instance;
   instance = C.get_value("instance");
//   instance = "dummy";
   config CONF(instance);

   const char* MYDATABASE;
   const char* MYTOPIC;
   const char* MYANSWER;
   const char* MYQUESTION;
        const char* USER;
        const char* PASS;
        const char* HOST;
   HOST = CONF.HOST.c_str();
        USER = CONF.USER.c_str();
        PASS = CONF.PASS.c_str(); 
   MYDATABASE = CONF.MYDATABASE.c_str();
   MYTOPIC = CONF.MYTOPIC.c_str();
   MYANSWER = CONF.MYANSWER.c_str();
   MYQUESTION = CONF.MYQUESTION.c_str();

   string TXT;
   int break_txt = 80;
   TXT = CONF.TXT;

   string format;   
   if(CONF.FORMAT == "large")
   {   
      format = "large";
   }
   else
   {   
      format = "topic";
   }

   string NAV;
   NAV = CONF.NAV;

   // we check for valid values in class config! 
   // we maybe here at the last point of the program!

   db = new Database();

   // Initialise the database - for future releases
   if (db->init() != DB_COMMAND_OK) {
      fprintf(stdout, "Unable to initialize database: %s\n\n", 
              db->errorMessage());
      exit(0);
        }

   // Connect to database on localhost
   if (db->connect(HOST, "", MYDATABASE, USER, PASS) != DB_CONNECTION_OK) { 
      fprintf(stdout, "Unable connect to database '%s': %s\n\n", 
              MYDATABASE, db->errorMessage());
      exit(0);
   }
//cout << "debug2\n";
   int topic_max = 0, question_max;
   string *tmp, *question_id, *question; 
   tmp = new string[10];
   string temp, navbar;
   int answer_max;
   // determine the numer of rows in topic...   
   res = db->exec("SELECT topic_id FROM %s ", MYTOPIC);
   tuple = res->getTuple();
   while (tuple != NULL)
   {
      //topic_max++;
      tuple = res->getTuple();
      topic_max++;
   }

   string topic[topic_max + 1];
   int topic_id[topic_max + 1];
   string topic_id_str[topic_max + 1];
   
   // now get the real topic_id's
   
   db->exec(res, "SELECT topic_id FROM %s ORDER by topic_id", MYTOPIC);
   //db->exec(res, "SELECT topic_id FROM %s", MYTOPIC);
        tuple = res->getTuple();
   i=0;
        while (tuple != NULL)
        {
                topic_id[i] = atoi(*(tuple));
      topic_id_str[i] = *(tuple);
                tuple = res->getTuple();
      i++;
        }
   
   // get the related topics...
   db->exec(res, "SELECT value FROM %s ORDER by topic_id", MYTOPIC);
   //db->exec(res, "SELECT value FROM %s", MYTOPIC);
        tuple = res->getTuple();
        i = 0;
   while (tuple != NULL)
        {
                topic[i] = *(tuple);
                tuple = res->getTuple();
      i++;
        }
   string Head, Foot, Index_Temp_f, Index_Header_f, Index_Footer_f;
   string Store_answer[20], Store_tmp[20], topic_f, anchor;
   char ch;
   string TXT_f = string(PATH) + "/" + TXT;
   string TXT_t = string(PATH) + "/" + TXT + ".temp";
   ofstream INDEX_TXT(TXT_f.c_str());
   ofstream TXT_TMP(TXT_t.c_str());
   ifstream txt_t(TXT_t.c_str());
   Index_Header_f = string(PATH) + "/" + string(HEADER);
   Index_Footer_f = string(PATH) + "/" + string(FOOTER);
   Index_Temp_f = string(PATH) + "/temp.html"; 
   ofstream Index_Temp(Index_Temp_f.c_str());
   ifstream Header_File(Index_Header_f.c_str());
   ifstream Footer_File(Index_Footer_f.c_str());
   if( !Header_File )
   {
      Head = h.html() + h.body("#ffffff", "#000000", "#3333FF", "#3333FF", "#FF0000");
      Head += h.title("Database Full Index") + "<p></p>\n";
   }
   else
   {
      while( Header_File )
      {
         Header_File.get(ch);
         Head += ch;
      }
   }
   if( !Footer_File )
   {
      Foot = "<font size=1>created by faq-system " + string(VERSION); 
      Foot += " <a href=mailto:" + string(AUTOR_MAIL) + ">" + string(AUTOR) + "</a></font>" + h._body() + h._html() + "\n";
   }
   else
   {
      while( Footer_File )
      { 
         Footer_File.get(ch);
         Foot += ch;
      }
   }
   // ################ fullindex.html ########################
        string Index_Name = string(PATH) + "/" + instance + ".html";
        ofstream Index(Index_Name.c_str());
   Index << Head;
   Index << "<a name=\"top\"></a>\n";
   Index << "<h2>Table of Contents</h2>\n";
   Index << "<p><hr></p>";

   if(TXT != "")
      INDEX_TXT << "TABLE OF CONTENTS\n\n";
   

   cout << h.html()
      << h.body("#ffffff", "#000000", "#3333FF", "#3333FF", "#FF0000");
   cout    << "<p>" << h.font("arial", "2");
   cout   << "<A HREF=\"" << URL << "/" << ADMIN << "/index.cgi?instance=" << instance << "\">[ reload site ]</A> ";
   cout << "<A HREF=\"" << URL << "/search.cgi?instance=" << instance << "&stage=prepare\">[ search ]</A> ";
   cout << "<A HREF=\"" << HTTP_BASE << "/" << instance << ".html\">[ full index ]</A> ";
   if(TXT != "")
      cout << "<A HREF=\"" << HTTP_BASE << "/" << TXT << "\">[ " << TXT << "]</A> ";
   cout << "<A HREF=\"" << HTTP_BASE << "/" ADMIN << "/help.html\">[ help ]</A> ";
   cout  << "</p>" << h._font(); 
   cout   << "<p>" << h.font("arial", "+2"); 
   cout   << "<b>  Topics </b>" <<  h._font();
   cout   << h.font("arial", "1") ;
   cout   << "  <A HREF=\"" << URL << "/" << ADMIN << "/topic.cgi?instance=" << instance; 
   cout   << "&stage=prepare\">[ new topic ]</A></p>" << endl;
   
   // tttttttttttttttttttt
   for(int t=0;t<topic_max;t++)
   {
      // create a string of t (!)
      char tee[5];
      sprintf(tee, "%d", t+1);
      
   if(format == "large")
   {
      // create an Index Entry
      Index << "<b>" << t + 1 << ". " << topic[t] << "</b><br>\n<ul>\n";
   }
   else
       {
      // create one file per topic...
      Index << "<a href=\"" << instance << "_topic_" << t + 1 << ".html\"><b>" 
      << t + 1 << ". " << topic[t] << "</b></a><br>\n<ul>\n";
   }
      topic_f = string(PATH) + "/" + instance + "_topic_" + tee + ".html";
      ofstream topic_file(topic_f.c_str());
   
   if(TXT != "")
   {
                        INDEX_TXT << t + 1 << ". " << topic[t] << "\n";
         TXT_TMP << "\n\n" << t + 1 << ". " << topic[t] << "\n\n";
   }
   if(format == "topic")
   {
      topic_file << Head;
      topic_file << "<a name=\"top\"></a>\n";
      topic_file << "\n<h1><u>" << t + 1 << ". " << topic[t] << "</u></h1>\n";
   
      navbar = "";
      navbar += "<a href=\"" + instance + ".html\">";
      if(NAV == "text")
         navbar += "[ top ]";
      else
                        navbar += "<img src=top.gif border=0 alt=TOP>";
      navbar += "</a> ";
      if(t == 0)
                {
         sprintf(tee, "%d", t+2);
                        navbar += "<a href=\"" + instance + "_topic_" + tee + ".html\">";
         if(NAV == "text")
            navbar += "[ next ]";
         else
            navbar += "<img src=next.gif border=0 alt=NEXT>";
         navbar += "</a> ";
                }
                else if(t == topic_max-1)
                {
         sprintf(tee, "%d", t);
                        navbar += "<a href=\"" + instance + "_topic_" + tee + ".html\">";
         if(NAV == "text")
            navbar += "[ previous ]";
         else
                                navbar += "<img src=previous.gif border=0 alt=PREVIOUS>";
         navbar += "</a> ";
                }
                else
                {
         sprintf(tee, "%d", t);
         navbar += "<a href=\"" + instance + "_topic_" + tee + ".html\">";
                        if(NAV == "text")
                                navbar += "[ previous ]";
                        else
                                navbar += "<img src=previous.gif border=0 alt=PREVIOUS>";
                        navbar += "</a> ";
         sprintf(tee, "%d", t+2);
         navbar += "<a href=\"" + instance + "_topic_" + tee + ".html\">";
                        if(NAV == "text")
                                navbar += "[ next ]";
                        else
                                navbar += "<img src=next.gif border=0 alt=NEXT>";
                        navbar += "</a> ";
                }
       


      topic_file << navbar << "\n<p> </p><hr>\n";
    
   }      
      
      cout    << "<p><b>" << h.font("arial", "3") << t + 1 << ". "; 
      cout   << topic[t] << h._font();
      cout   << h.font("arial", "1") << "  <A HREF=\"" << URL ;
      cout   << "/" << ADMIN << "/question.cgi?instance=" << instance << "&stage=prepare&topic_id="; 
      cout   << topic_id[t] << "\">[ ask ]</A> "; 
      cout   << "<A HREF=\"" << URL << "/" << ADMIN << "/modify.cgi?instance=" << instance 
         << "&stage=prepare&mode=topic&topic_id="; 
      cout    << topic_id[t] << "\">[ modify ]</A> "; 
      cout << "<A HREF=\"" << URL << "/" << ADMIN << "/delete.cgi?instance=" << instance
      << "&stage=prepare&mode=topic&topic_id=" << topic_id[t] << "\">[ delete ]</A>"
      << h._font(); 
      cout   << h._font();
      cout   << "</b></p>\n";
      db->exec(res, "SELECT question_id FROM %s WHERE topic_id = %d", MYQUESTION, topic_id[t]);
           tuple = res->getTuple();
      question_max = 0;
             while (tuple != NULL)
           {
                          question_max++; 
                   tuple = res->getTuple();
      }
      //cout << "debug IV\n";   
      question = new string[question_max];
      question_id = new string[question_max];

      db->exec(res, "SELECT value FROM %s WHERE topic_id = %d ORDER by question_id", MYQUESTION, topic_id[t]);
                tuple = res->getTuple();
      i=0;
                while (tuple != NULL)
                {
                        question[i] = *(tuple);
         tuple = res->getTuple();
         i++;
                }
      db->exec(res, "SELECT question_id FROM %s WHERE topic_id = %d ORDER by question_id", MYQUESTION, topic_id[t]);
                tuple = res->getTuple();
      i=0;
                while (tuple != NULL)
                {
         question_id[i] = *(tuple);
                        tuple = res->getTuple();
                        i++;
                }   

      for(int b=0; b<question_max; b++)
      {
         db->exec(res, "SELECT value FROM %s WHERE question_id = %s", MYANSWER, question_id[b].c_str());
         tuple = res->getTuple();
         answer_max = 0;
         while (tuple != NULL)   
         {
            if( *(tuple) == NULL)
            {
               answer_max=0;
               break;
            }
            answer_max++;
            tuple = res->getTuple();
         }

         cout << h.font("arial", "2") << endl; 
         cout << "         ";
         if( answer_max != 0 )
         {
            // create anchor name
            i=0;
            db->exec(res, "SELECT value FROM %s WHERE question_id = %s", MYANSWER, question_id[b].c_str());
                                tuple = res->getTuple();
            int p;
            string produce, store, store_txt, link, caption;
            //char *link, *caption;
            //link = new char[250];
            //caption = new char[250];
            while (tuple != NULL)
                                {
                                        temp = *(tuple);
               int length = temp.length();
               for(int pos=0; pos<length;pos++)
               {
                  if(temp[pos] == '#')
                  {
                     if(temp[pos+1] == '#')
                     {
                        pos += 2;
                        p=0;
                        while(temp[pos] != '#')
                        {
                           link += temp[pos];
                           p++;
                           pos++;
                        } 
                        pos++;
                        p=0;
                        while(temp[pos] != '#')
                        {
                           caption += temp[pos];
                           p++;
                           pos++;
                        }
                        if(TXT != "")
                                                                        store_txt += caption + " " + link;      
                        store += "<a href=\"";
                        if(link[0] == '_')
                        {
                           string topic_link;
                           int topic_link_pos = 0;
                           int topic_link_len = link.length();
                           for(int p=0;p<topic_link_len;p++)
                           {
                              if(link[p] == '_')
                              {
                                 if(topic_link_pos == 0)
                                    topic_link_pos++;
                              }
                              else
                              {
                                 if(topic_link_pos == 1)
                                 {      
                                    topic_link += link[p];
                                    if(link[p+1] == '_')
                                       topic_link_pos++;
                                 }
                              }
                           }      
                           store += string(HTTP_BASE) + "/";
                             if(format == "large")
                              store += instance + ".html#";
                             else
                              store += instance + "_topic_" + topic_link + ".html#";
 
                        }
                        store += link + "\">" + caption + "</a>";
                        link = "";
                        caption = "";   
                     }
                     else
                     {
                        store += temp[pos];
                        store_txt += temp[pos];
                        if(pos == break_txt)
                           store_txt += "\n";
                     }
                  }
                  else
                  {
                     store += temp[pos];
                     store_txt += temp[pos];
                     if(pos == break_txt)
                                                                        store_txt += "\n";
                  }
               }
               Store_tmp[i] = store_txt;
               Store_answer[i] = store;
               store = "";            
               store_txt = "";                      
                                        tuple = res->getTuple();
                                        i++;
                                } 
            Index << "<li>"; 
            if(format == "large")
            {
               Index << "<a href=\"#_" << topic_id[t] << "_" << b + 1
               << "\">" << t + 1 << "." << b + 1 << ". " << question[b] << "</a><br>\n";


               Index_Temp << "<a name=\"_" << t + 1 << "_" << b + 1  << "\"></a>\n";
               Index_Temp << "<h3>" << t + 1 << "." << b + 1 << ". " << question[b] << "</h3>\n";


               // here comes the answer:
               for(int m=0;m<i;m++)
               {
                  Index_Temp << Store_answer[m].c_str() << "<br></br>\n";
               }
               if(NAV == "text")
               {
                  Index_Temp << endl << "<br>" << h.font("arial", "1");
                  Index_Temp << "<br></br><p><a href=\"#top\">[ top ]</a></p>"
                  << h._font();
               }
               else
               {
                  Index_Temp << endl << "<br><br></br><p><a href=\"#top\">"
                  << "<img src=\"top.gif\" border=0 width=\"10\" height=\"10\">"
                  << "</a></p>";   
               }
               Index_Temp << "<hr><p> </p>" << endl;
            }
            else
            {
               Index << "<a href=\"" << instance << "_topic_" << t + 1 << ".html#_"
               << t + 1 << "_" << b + 1
               << "\">" << t + 1 << "." << b + 1 << ". " << question[b] << "</a><br>\n";   
               
               topic_file << "<a name=\"_" << t + 1 << "_" << b + 1 << "\"></a>\n";
               topic_file << "<h3>" << t + 1 << "." << b + 1 << ". " << question[b] << "</h3>\n";
               // here comes the answer:
               for(int m=0;m<i;m++)
               {
                  topic_file << Store_answer[m].c_str() << "<br></br>\n";
               } 
               if(NAV == "text")
                                        {
                                                topic_file << endl << "<br>" << h.font("arial", "1")
                                                << "<br></br><p><a href=\"#top\">[ top ]</a></p>"
                                                << h._font();
                                        }
                                        else
                                        {
                                                topic_file << endl << "<br><br></br><p><a href=\"#top\">"
                                                << "<img src=\"top.gif\" border=0 width=\"10\" height=\"10\">"
                                                << "</a></p>";
                                        }
               topic_file << h._font() << "<hr><p> </p>\n";
            }
            
            if(TXT != "")
                                {
                                        TXT_TMP << "    " << t + 1 << "." << b + 1 << ". " << question[b] << "\n\n";
                                        INDEX_TXT << "   " << t + 1 << "." << b + 1 << ". " << question[b] << "\n";
               for(int m=0;m<i;m++)
                  TXT_TMP << Store_tmp[m].c_str() << "\n\n\n";
                                }
            cout << "<A HREF=\"" << URL 
             << "/getanswer.cgi?instance=" << instance << "&stage=dbadmin&question_id=";  
            cout << question_id[b] << "\">" << t + 1 << "." << b  + 1 << ". ";
            cout << "<b>" << question[b] << "</b>";
            cout << "</A><b>" << h.font("arial","1") 
            << " [[ _" << t + 1 << "_" << b + 1 << " ]]" << h._font() << "</b>";
            cout << "</A>";
         }
         else
         {

            cout << t + 1 << "." << b + 1 << ". ";
            cout << "<b>" << question[b] << "</b>";
         }

         cout << h._font();
         cout << h.font("arial","1") << "  <A HREF=\"" << URL 
         << "/" << ADMIN << "/answer.cgi?instance=" << instance << "&stage=prepare&question_id=";
         cout << question_id[b] << "&topic_id=" << topic_id[t];
         cout << "\">[ answer ]</A> ";
         cout << " <A HREF=\"" << URL << "/" << ADMIN << "/modify.cgi?instance=" << instance 
            << "&stage=prepare&mode=question&question_id=";
         cout << question_id[b] << "&topic_id=" << topic_id[t];
         cout << "\">[ modify ]</A> " ;
         
         cout << "<A HREF=\"" << URL << "/" << ADMIN << "/delete.cgi?instance=" << instance
         << "&stage=prepare&mode=question&question_id=" << question_id[b] 
         << "\">[ delete ]</A> " 
         << h._font();
         cout << "<br>" << endl; 
      } 
      Index << "</ul>\n";
      if(TXT != "")
         INDEX_TXT << "\n";

      topic_file << "</ul>\n"; 
      if(format == "topic")
      {
         topic_file << "<P></P>" << navbar;
         topic_file << "<br></br>" << Foot;
      }   
      cout << "<P></P><br></br>";      
   }
   if(format == "large")
   {
      Index << "<p></p><p></p><hr><p></p><p></p>\n";
      char buffer[1000];
      ifstream f(Index_Temp_f.c_str());
      while ( f )
      {
         f.getline(buffer, 1000);
         Index << buffer << "\n";
      }
   }
   if(TXT != "")
   {
      TXT_TMP.close();
      INDEX_TXT << "\n\n\n\n";
      char buf[1000];
      //ifstream txt_t(TXT_t.c_str());
      while ( txt_t )
      {
         txt_t.getline(buf, 1000);
         INDEX_TXT << buf << "\n";
      }
      INDEX_TXT << "\n\n\ncreated by faq-system " << VERSION << "\n";
   }
   Index << Foot;   
   cout << "<p><font size=1>faq-system " << VERSION << " . © 1999 Thomas Linden</font></p>";
   cout << h._body() << h._html();
   
   delete res;         // Drop buffer
   delete db;         // Close connection
}
                                                                                                                                                                                                                                                        faq-system-0.3.5/modify.cc                                                                          100644     764     144        12754  6727343572  14355  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  #include "conf.h"

int main(void)
{
        //int i;
        char **tuple;
        Database *db;
        DBResult *res;

        db = new Database();

   cgi C;
        C.initPage();

   string instance;
        instance = C.get_value("instance");
        config CONF(instance);

   const char* MYDATABASE;
        const char* MYTOPIC;
        const char* MYANSWER;
        const char* MYQUESTION;
        const char* USER;
        const char* PASS;
        const char* HOST;
        HOST = CONF.HOST.c_str();
        USER = CONF.USER.c_str();
        PASS = CONF.PASS.c_str(); 
        MYDATABASE = CONF.MYDATABASE.c_str();
        MYTOPIC = CONF.MYTOPIC.c_str();
        MYANSWER = CONF.MYANSWER.c_str();
        MYQUESTION = CONF.MYQUESTION.c_str();

        string stage, mode, answer, topic, question, question_id, answer_id, topic_id, keys;
   string TABLE, hidden_mode, hidden_id, id, action, value;
   
   if (db->init() != DB_COMMAND_OK) {
                fprintf(stdout, "Unable to initialize database: %s\n\n",
                        db->errorMessage());
                exit(0);
        }

        // Connect to database on localhost
   if (db->connect(HOST, "", MYDATABASE, USER, PASS) != DB_CONNECTION_OK) { 
                fprintf(stdout, "Unable connect to database '%s': %s\n\n",
                        MYDATABASE, db->errorMessage());
                exit(0);
        } 

   stage = C.get_value("stage");
   mode = C.get_value("mode");

   HTML h;
   
   cout << h.html() << h.body("#ffffff") << endl;

   if (stage == "prepare")
   {
      if (mode == "topic")
      {
         topic_id = C.get_value("topic_id");
         hidden_id = topic_id;
         TABLE = MYTOPIC;
      }
      else if (mode == "question")
      {
         question_id = C.get_value("question_id");
         hidden_id = question_id;
         TABLE = MYQUESTION;
      }
      else if (mode == "answer")
      {
         answer_id = C.get_value("answer_id");
         hidden_id = answer_id;
         TABLE = MYANSWER;
      }

      id = mode + "_id";

      res = db->exec("SELECT value FROM %s WHERE %s = %s", TABLE.c_str(), id.c_str(), hidden_id.c_str());
                tuple = res->getTuple();
                while (tuple != NULL)
                {
                        value = *(tuple);
         tuple = res->getTuple();
                }


                cout << "<form name=modify action=\"" << URL << "/" << ADMIN << "/modify.cgi\" method=post>" << endl
                << h.font("arial","2")
                << "<b>Modify a " << mode << ".</b>"
                << h._font() << "<br></br>" << endl
                << h.font("arial","2") << mode << ": " << h._font() << "<br></br>" << endl
                << h.textarea(mode, value, "15", "80") << "<br></br>" << endl;
      if (mode != "topic")
      {
         db->exec(res,"SELECT keywords FROM %s WHERE %s = %s", TABLE.c_str(), id.c_str(), hidden_id.c_str());
                   tuple = res->getTuple();
                   while (tuple != NULL)
                   {
                           keys = *(tuple);
                           tuple = res->getTuple();
                   }
         cout << h.font("arial","2") << "key words: " << h._font() << "<br></br>" << endl    
         << h.textarea("keys", keys, "4", "30") << "<br></br>" << endl;
      }
                cout << h.in_hidden(id, hidden_id) << endl
      << h.in_hidden("mode", mode) << endl
      << h.in_hidden("stage", "save") << endl
                << h.in_submit("Modify")
      << h.in_hidden("instance",instance)
                << h.in_reset("Clear") << endl
                << h._form() << endl; 
   }
   else
   {
      // Modify stage
      if (mode == "topic")
                {
                        hidden_id = C.get_value("topic_id");
                        value = C.get_value("topic");
                        TABLE = MYTOPIC;
                }
                else if (mode == "question")
                {
                        hidden_id = C.get_value("question_id");
                        value = C.get_value("question");
                        TABLE = MYQUESTION;
                }
                else if (mode == "answer")
                {
                        hidden_id = C.get_value("answer_id");
                        value = C.get_value("answer");
                        TABLE = MYANSWER;
                }
      

      id = mode + "_id";

      string tmp("");
      int len;
      len = value.length();
      for(int i=0;i<len;i++)
      {
         if(value[i] == char(39))
            tmp += "\\'";
         else
            tmp += value[i];
      }
   
      res = db->exec("UPDATE %s SET value = '%s' WHERE %s = %s", TABLE.c_str(), tmp.c_str(), id.c_str(), hidden_id.c_str()); 
      if (res->status() != DB_COMMAND_OK) {
                fprintf(stdout, "Can't update into table '%s': %s\n\n", TABLE.c_str(), db->errorMessage());
                        delete res;
                        delete db;
                        exit(0);
                }
/*
      cout << "Command: <b><br>" << endl;
      fprintf(stdout, "UPDATE %s SET keys = '%s' WHERE %s = %s", TABLE.c_str(), keys.c_str(), id.c_str(), hidden_id.c_str());
      cout << "</b><br></br>\n";
*/      

      if (mode != "topic")
      {
         keys = C.get_value("keys");
         db->exec(res, "UPDATE %s SET keywords = '%s' WHERE %s = %s", TABLE.c_str(), keys.c_str(), id.c_str(), hidden_id.c_str());
                   if (res->status() != DB_COMMAND_OK) {
                   fprintf(stdout, "Can't update into table '%s': %s\n\n", TABLE.c_str(), db->errorMessage());
                           delete res;
                           delete db;
                           exit(0);
                   }
      } 
   
      cout << "<b>Data in table \"" << TABLE << "\" updated</b><br></br>\n";
   }
   Pro p; 
   cout << p.back("dbadmin", instance) << endl;
   cout << h._body() << h._html() << endl;

}
                    faq-system-0.3.5/question.cc                                                                        100644     764     144         6213  6727307346  14705  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  #include "conf.h"

int main(void)
{
   //int i;
   char **tuple;
   Database *db;
   DBResult *res;

   db = new Database();

   cgi C;
        C.initPage();

   Pro p;

        string instance;
        instance = C.get_value("instance");
        config CONF(instance);

   const char* MYDATABASE;
        const char* MYTOPIC;
        const char* MYANSWER;
        const char* MYQUESTION;
        const char* USER;
        const char* PASS;
        const char* HOST;
        HOST = CONF.HOST.c_str();
   USER = CONF.USER.c_str();
        PASS = CONF.PASS.c_str(); 
        MYDATABASE = CONF.MYDATABASE.c_str();
        MYTOPIC = CONF.MYTOPIC.c_str();
        MYANSWER = CONF.MYANSWER.c_str();
        MYQUESTION = CONF.MYQUESTION.c_str();

   // Initialise the database - for future releases
   if (db->init() != DB_COMMAND_OK) {
      fprintf(stdout, "Unable to initialize database: %s\n\n", 
              db->errorMessage());
      exit(0);
        }

        if (db->connect(HOST, "", MYDATABASE, USER, PASS) != DB_CONNECTION_OK) {
                fprintf(stdout, "Unable connect to database '%s': %s\n\n",
                MYDATABASE, db->errorMessage());
                exit(0);
        }
   
   string stage;
   string topic_id;
        topic_id = C.get_value("topic_id");
   stage = C.get_value("stage");

   HTML h;

   cout << h.html()
        << h.body("#ffffff") << endl;

   if( stage == "prepare" )
   {
      res = db->exec("SELECT value FROM %s WHERE topic_id = '%s'", MYTOPIC, topic_id.c_str());
                tuple = res->getTuple();
                while (tuple != NULL)
                {
                        cout << "<h2>" << *(tuple) << "</h2>\n";
                        tuple = res->getTuple();
                }
      cout << "<form name=ask action=\"" << URL << "/" << ADMIN << "/question.cgi\" method=post>" << endl
      << h.font("arial","2")
      << "Enter new question:"
      << h._font() << "<br></br>" << endl
      << h.font("arial","2") << "Question:" << h._font() << "<br></br>" << endl
      << h.textarea("question", "", "8", "60") << "<br></br>" << endl
      << h.font("arial","2") << "Keywords:" << h._font() << "<br></br>" << endl
      << h.textarea("keys", "", "4", "30") << "<br></br>" << endl
      << h.in_hidden("topic_id", topic_id) << endl
      << "<input type=hidden name=instance value=\"" << instance << "\">\n"
      << h.in_hidden("stage", "save") << endl
      << h.in_submit("Save") 
      << h.in_reset("Clear") << endl
      << h._form() << endl;
   }
   else
   {
      string ques, ke, question, keys;
      ques = C.get_value("question");
      if( ques == "" )
      {
         cout << h.title("Error!")
         << "<h2>Value for \"QUESTION\" was empty!</h2>" << endl;
      }
      else
      {
         ke = C.get_value("keys");   
         
         question = p.parse(ques);
         keys = p.parse(ke);
   
         res = db->exec("INSERT INTO %s VALUES(0, %s, '%s', '%s')",MYQUESTION, topic_id.c_str(), question.c_str(), keys.c_str());
         if (res->status() != DB_COMMAND_OK) {
            fprintf(stdout, "Can't insert into table '%s': %s\n\n", MYQUESTION, db->errorMessage());
            delete res;
            delete db;
            exit(0);
         }
         cout << "Data inserted<br></br>\n";
         cout << p.back("dbadmin", instance) << endl;
      }
   }
   cout << h._body()
   << h._html()
   << endl;   
   delete res;         // Drop buffer
   delete db;         // Close connection
}
                                                                                                                                                                                                                                                                                                                                                                                     faq-system-0.3.5/search.cc                                                                          100644     764     144        11675  6727307346  14333  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  #include "conf.h"

int main(void)
{
   //int i;
   char **tuple;
   Database *db;
   DBResult *res;

   db = new Database();

   cgi C;
        C.initPage();

   string instance;
        instance = C.get_value("instance");
        config CONF(instance);

   const char* MYDATABASE;
        const char* MYTOPIC;
        const char* MYANSWER;
        const char* MYQUESTION;
        const char* USER;
        const char* PASS;
        const char* HOST;
        HOST = CONF.HOST.c_str();
   USER = CONF.USER.c_str();
        PASS = CONF.PASS.c_str(); 
        MYDATABASE = CONF.MYDATABASE.c_str();
        MYTOPIC = CONF.MYTOPIC.c_str();
        MYANSWER = CONF.MYANSWER.c_str();
        MYQUESTION = CONF.MYQUESTION.c_str();

   // Initialise the database - for future releases
   if (db->init() != DB_COMMAND_OK) {
      fprintf(stdout, "Unable to initialize database: %s\n\n", 
              db->errorMessage());
      exit(0);
        }

   string stage;
   stage = C.get_value("stage");
      

   // Connect to database on localhost
   if (db->connect(HOST, "", MYDATABASE, USER, PASS) != DB_CONNECTION_OK) { 
      fprintf(stdout, "Unable connect to database '%s': %s\n\n", 
              MYDATABASE, db->errorMessage());
      exit(0);
   }

   HTML h;
   cout << h.html()
        << h.body("ffffff") << endl;
   if(stage == "prepare")
   {
      string url("");
      url = string(URL) + "/search.cgi";
      cout << "<h2>Search the database</h2>\n"
      << h.font("arial","2") << endl
      << "Please enter your search query:\n<br></br>"
      << h.form( "search", url, "POST") << endl
      << h.textarea("expression", "", "2", "30") << "<br></br>" << endl
      << "Select a search method:<br>"
      << "<input type=radio name=mode value=PHRASE checked> An exact phrase match<br>\n"
      << "<input type=radio name=mode value=AND> Matches on all words (AND)<br>\n"
      << "<input type=radio name=mode value=OR> Matches on any word (OR)<br>\n"
      << "<input type=hidden name=instance value=\"" << instance << "\">\n"
      << "<br></br>\n"
      << "<input type=radio name=keymode value=KEY checked> Search only in \"keywords\"<br>\n"
      << "<input type=radio name=keymode value=ALL> Search the whole database<br>\n"
      << h.in_submit(" Search ") << endl
                << h._form() << endl   
      << h._body()
      << h._html()
      << endl;   
   }
   else
   {
      string expression, mode, keymode, usemode, tmp("");
      expression = C.get_value("expression");
      if(expression == "")
      {   
         cout << "Nothing to search!<br></br>\n";
         cout << "<A HREF=\"" << URL << "/search.cgi?instance=" 
         << instance << "&stage=prepare" << "\">[ new search ]</A>\n";
         cout << h._body() << h._html();
         exit(0);
      }
      mode = C.get_value("mode");
      keymode = C.get_value("keymode");
      int len, count=0;
      len = expression.length();
      tmp = "SELECT DISTINCT question_id from ";
      tmp += string(MYANSWER) + " WHERE ";
      if(mode != "PHRASE")
      {
         if(keymode == "ALL")
            tmp += "(value like '%";
         else
                           tmp += "keywords like '%";
         
         for(int i=0;i<len;i++)
         {
            if(expression[i] == ' ')
            {
               if(keymode == "ALL")
               {
                  tmp += "%') " + mode;
                  tmp += " (value like '%";
               }
               else
               {
                                                tmp += "%' " + mode;
                                                tmp += " keywords like '%";
                                        }
            }
            else 
               tmp += expression[i];
               
         }
         if(keymode == "ALL")
            tmp += "%')";
         else
            tmp += "%'";
      }
      else
      {
         if(keymode == "ALL")
                           tmp += "value like '%";
         else
            tmp += "keywords like '%";
         tmp += expression + "%'";
      }
      cout << "<h2>Search Results:</h2>";
      res = db->exec("%s", tmp.c_str());
      tuple = res->getTuple();
           while (tuple != NULL)
      {
         count++;
         tuple = res->getTuple();
           }
      cout << "<p>" << h.font("arial","2")
      << count << " ";
      if(count <= 1)
         cout << "match";
      else
         cout << "matches"; 

      cout << " found in database:</p>" << h._font();
      cout << "<hr>\n";
      int i=0;
      string answer_id[count+1], question_id[count+1];
      db->exec(res, "%s", tmp.c_str()); 
      tuple = res->getTuple();
      while (tuple != NULL)
      {
         question_id[i] = *(tuple);
         tuple = res->getTuple();
         i++;
      }   

      
      // start to output the results:
      i = 0;

      for(int c=0; c<count;c++)
      {
         db->exec(res, "SELECT value FROM %s WHERE question_id = %s", MYQUESTION, question_id[c].c_str());
         tuple = res->getTuple();
         while (tuple != NULL)
         {
            cout << h.font("arial","2")
                                << "<A HREF=\"" << URL << "/getanswer.cgi?instance=" << instance << "&question_id="
                                << question_id[c] << "\">" << *(tuple)
                                << "</A><br></br>" << h._font() << endl;
                                tuple = res->getTuple();
         }
      }
      cout << "<hr>\n";
      cout << "<A HREF=\"" << URL << "/search.cgi?instance=" << instance << "&stage=prepare"
      << "\">[ new search ]</A>\n";
      cout << h._body() << endl
                << h._html();   
   }


   delete res;         // Drop buffer
   delete db;         // Close connection

}
                                                                   faq-system-0.3.5/topic.cc                                                                           100644     764     144         4403  6727307346  14153  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  #include "conf.h"

int main(void)
{
   //int i;
   //char **tuple;
   Database *db;
   DBResult *res;

   db = new Database();

   cgi C;
        C.initPage();

   Pro p;

   string instance;
        instance = C.get_value("instance");
   config CONF(instance);
   
   const char* MYDATABASE;
        const char* MYTOPIC;
        const char* MYANSWER;
        const char* MYQUESTION;
        const char* USER;
        const char* PASS;
        const char* HOST;
        HOST = CONF.HOST.c_str();
   USER = CONF.USER.c_str();
        PASS = CONF.PASS.c_str(); 
        MYDATABASE = CONF.MYDATABASE.c_str();
        MYTOPIC = CONF.MYTOPIC.c_str();
        MYANSWER = CONF.MYANSWER.c_str();
        MYQUESTION = CONF.MYQUESTION.c_str();

   // Initialise the database - for future releases
   if (db->init() != DB_COMMAND_OK) {
      fprintf(stdout, "Unable to initialize database: %s\n\n", 
              db->errorMessage());
      exit(0);
        }

   string topic;
   string stage;
   stage = C.get_value("stage");
   topic = C.get_value("topic");

   HTML h;
        cout << h.html()
        << h.body("#ffffff") << endl;

   if( stage == "prepare" )
   {
      string url;
      url = string(URL) + "/" + string(ADMIN) + "/topic.cgi";
      cout << h.title("Add Topic") << endl
      << "<h2>Database Instance: " << instance << "</h2>" << endl
      << h.form( "store", url, "POST") << endl
      << h.font("arial","2") << "Topic:" << h._font() << "<br></br>" << endl      
      << h.textarea("topic", "", "4", "30") << "<br></br>" << endl
      << "<input type=hidden name=instance value=\"" << instance << "\">\n"
      << h.in_submit("Save") << endl
      << h._form() << endl;
   }
   else
   {
      // Connect to database on localhost
      if (db->connect(HOST, "", MYDATABASE, USER, PASS) != DB_CONNECTION_OK) { 
         fprintf(stdout, "Unable connect to database '%s': %s\n\n", 
                 MYDATABASE, db->errorMessage());
         exit(0);
      }

      string tmp("");
      tmp = p.parse(topic);

      res = db->exec("INSERT INTO %s VALUES(0, '%s')",MYTOPIC, tmp.c_str());
      if (res->status() != DB_COMMAND_OK) {
         fprintf(stdout, "Can't insert into table '%s': %s\n\n", MYTOPIC, db->errorMessage());
         delete res;
         delete db;
         exit(0);
      }
      
      cout << "Data inserted\n"
      << p.back("dbadmin", instance);
   }
   cout << h._body()
   << h._html()
   << endl;   

   delete res;         // Drop buffer
   delete db;         // Close connection
}
                                                                                                                                                                                                                                                             faq-system-0.3.5/cgi.h                                                                              100644     764     144        20641  6727307346  13463  0                                                                                                    ustar   thomas                          users                                                                                                                                                                                                                  /*
 Copyright (c) 1998 Thomas Linden.

 You have my permission to modify, copy, mutilate, or spindle this code as 
 long as you don't use my name to make money.

 The software comes "as-is" and I cannot make any guarentees that is correct.

 It is distributed under the terms of the GNU General Public License

 Portions of this code was developed by Kelly Black at the University of New Hampshire,
 as these are the routines initPage() and getFormdata(), wich parses the browser
 input. These routines was taken from his cgiClass.h. Thanks to Kelly.         

*/


#include <ctype.h>
#include <string.h>  // some c code here...
#include <sys/types.h>
#include <sys/stat.h>

class cgi {

public:
    // constructor
    cgi(void);

    // start page.  Must be first thing called.
    // If non-null argument given it will load the
    // URL given in string.
    void initPage(char* = NULL);

    // this subroutine is called, if a new cgi object has been initialized
    // it starts the routine getFormdata and converts the resuls (char*) to
    // C++ strings (class string) and stores them in _name[100] and _value[100]
    // I hope 100 is enough...
    void get_all();

    // the data from the form, a string array of 100 entrys    
    string _name[100];
    string _value[100];
    int _num;

    // Environment variables of interest
    string getRefer(void);
    string getAgent(void);
    string getPragma(void);
    string getAccept(void);
    string getPath(void);
    string getPathInfo(void);
    string getPathTranslated(void);
    string getServerSoftware(void);
    string getServerNamer(void);
    string getServerPort(void);
    string getRemoteHost(void);
    string getRemoteAddress(void);
    string getGateway(void);
    string getProtocol(void);
    const char* getRequestMethod(void);
    string getScriptName(void);
    const char* getQueryString(void);
    string getSHLVL(void);
    string getPWD(void);
    string getLogName(void);
    string getUser(void);
    string getHost(void);
    string getHostType(void);

    // Get data from a form.
    // returns number of fields as well as
    // character arrays to the fields.  The
    // first argument returns as the data within the
    // fields and the second argument returns the names
    // of the fields.
    void getFormData(char** &,char** &,int &);
    long getContentLength(void);

    // returns the value of the specified formelement as string
    string get_value(const string& form_name);

    enum Method {
   GET = 0,
   POST = 1
    };

    void turnErrorPrintingOn(void);
    void turnErrorPrintingOff(void);

protected:
private:
    void Error(const char* ,const char* = NULL,const char* = NULL);

    int outputError;

};



// Constructor.  Not much to do here but
// initialize the variables
cgi::cgi(void) {
    outputError = 1;
    get_all();
}


void cgi::get_all()
{
 

Scripts recomendados

Estrutura de serviço

Bubble Sort

Gerador de wordlist

teste

C++ Banco de Dados


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts