00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <iostream>
00013 #include <iomanip>
00014 #include "cgiTemplates.h"
00015 #include "connectstring"
00016 #include "forms.h"
00017 #include "ocTypes.h"
00018 #include "ocString.h"
00019 #include "read_write_base.hpp"
00020 #include "forms_base.hpp"
00021 #include "cgiTemplates.h"
00022 #include "Document.hpp"
00023 #include "openLogin.h"
00024 #include "diaButtons.h"
00025
00026 using namespace std;
00027 openLogin oLogin;
00028
00029 #include "sublist_base.hpp"
00030 #include "ocFileSys.h"
00031
00032
00033 class Document_List: public sublist_base
00034 {
00035
00036 public:
00037
00038 Document_List(cgiScript&sc):sublist_base(sc){;}
00039 ~Document_List(){;}
00040
00041 string Filter;
00042
00043 bool list_display( void )
00044 {
00045 bool breturn = true;
00046 string sql = "select "
00047 "Id, "
00048 "Category, "
00049 "Name, Sequence "
00050 "from Document ";
00051 if( Filter.length() )
00052 {
00053 sql += "where Category like '" ;
00054 sql += Filter;
00055 sql += "%'";
00056 }
00057 sql += " order by Sequence, Category, Name ";
00058 hotCol=-2;
00059 editLink = listTemplate.getParagraph("peerlink");
00060 editLink = editLink.replace("$prog$","Document_Popup.cgi");
00061 string heading = "Id| "
00062 "Category| "
00063 "Name| Sequence " ;
00064 webIO << "<form action='Document_Popup.cgi'><h3>Filter by Category: <input type='text' name='Filter' value='";
00065 webIO << Filter << "'> <input type='submit' value='Go'></h3></form>" << endl;
00066 emitHeadings(heading);
00067 getData( sql );
00068 emitData();
00069 ocString list_new = listTemplate.getParagraph("peernew");
00070 ocString url = "Document_Popup.cgi";
00071 if( Filter.length() )
00072 {
00073 url+="?Filter=";
00074 url+=Filter;
00075 }
00076
00077 webIO << list_new.replace("$location",url.c_str()).replace("$cols","3").replace("Item","Document");
00078 emitEnd();
00079 return breturn;
00080 }
00081 };
00082 class Document_form: public Document_Obj, public forms_base
00083 {
00084 public:
00085 Document_form(cgiScript & script):Document_Obj(),forms_base(script)
00086 {
00087 setKey(*this);
00088 }
00089 virtual ~Document_form(){;}
00090
00091 void form_id_transfer( void )
00092 {
00093 llongFXfer( "Id", Id );
00094 }
00095 void form_data_transfer( void )
00096 {
00097 stringFXfer( "Category", Category);
00098 stringFXfer( "Name", Name);
00099 stringFXfer( "Description", Description);
00100 stringFXfer( "Filename", Filename);
00101 if( Filename.length() == 0 )
00102 stringFXfer( "URL2", Filename);
00103 boolFXfer( "Visible", Visible);
00104 intFXfer( "Sequence", Sequence);
00105 }
00106
00107 bool dbf_action( string mode, changeMap & changes )
00108 {
00109 if( mode=="d" )
00110 {
00111 ocFileSys fs;
00112 string remPath = "./media/" + Filename;
00113 fs.remove(remPath);
00114 }
00115 return db_action( mode, changes );
00116 }
00117
00118
00119 bool form_display( void )
00120 {
00121 bool breturn = true;
00122 ocString sql;
00123 script << makeTop("Document_Popup.cgi", "Document")
00124 << formTemplate.getParagraph("advanced_begin");
00125 script << makeStaticBox("Id", "Id", Id ,"8");
00126 script << "<br class='clearall'>" << endl;
00127 script << formTemplate.getParagraph("advanced_end");
00128
00129 script << makeTextBox("Category", "Category", Category ,"125","35");
00130 script << "<br class='clearall'>" << endl;
00131
00132 script << makeTextBox("Name", "Name", Name ,"125","35");
00133 script << "<br class='clearall'>" << endl;
00134
00135 script << makeTextArea("Description", "Description", Description ,"5","80");
00136 script << "<br class='clearall'>" << endl;
00137
00138 script << ocString(makeFileBox( "Filename", "Filename", Filename, "30","255", "id='Filename'"))
00139 .replace(" class=\"ctrlgroup\"","").replace(" class=\"control\"","")
00140 << makeHiddenBox( "URL2", Filename ) << "<br class='clearall'>" << endl;
00141
00142 script << makeBoolBox("Visible", "Visible", Visible );
00143 script << "<br class='clearall'>" << endl;
00144
00145 script << makeTextBox("Sequence", "Sequence", Sequence ,"8","8");
00146 script << "<br class='clearall'>" << endl;
00147
00148 script << diaButtons( key() ,
00149 " Insert Document ",
00150 " Update Document ",
00151 " Delete Document ",
00152 "",
00153 "");
00154 script << makeBottom( m_result ) << endl;
00155 return breturn;
00156 }
00157 };
00158
00159
00160 int main( int argcount, char ** args )
00161 {
00162 cgiScript script( "text/html", false , "./documents" );
00163 Document_form myFrm(script);
00164
00165 if( oLogin.testLoginStatus() )
00166 {
00167 script.closeHeader();
00168 cgiTemplates pgTemplate;
00169 pgTemplate.load("Templates/childPane.htmp");
00170
00171 script << ocString(pgTemplate.getParagraph("top"))
00172 .replaceAll("$heading$","Document");
00173
00174 myFrm.loadControlTemplates("Templates/childdivform.htmp");
00175 myFrm.form_action();
00176 myFrm.form_display();
00177
00178 Document_List DocumentList(script);
00179 DocumentList.loadListTemplates("Templates/spawninglist.htmp");
00180 script << "<div class=\"ui\">" << endl;
00181 script << "<div class='heading'>Document List:</div>" << endl;
00182 DocumentList.Filter = script.ClientArguments()["Filter"].c_str();
00183 DocumentList.list_display();
00184 script << "</div>" << endl;
00185
00186 ocString end = pgTemplate.getParagraph("bottom");
00187 script << end;
00188 }
00189 else
00190 {
00191 script << "<html><body>"
00192 << "<a href='javascript:window.close()'><h1>You are not logged in</h1></a>"
00193 << "</body></html>" << endl;
00194 }
00195 }
00196
00197 #include "read_write_base.cpp"
00198 #include "forms_base.cpp"
00199
00200