00001
00002
00003
00004
00005
00006 #include <string>
00007
00008 #include "openLogger.h"
00009 using namespace std;
00010
00011
00012 string baseUrl;
00013
00014 #include "w3intranet.h"
00015 #include "page_enhancements.hpp"
00016 #include "Document.hpp"
00017
00018 class document_list_functor: public base_functor
00019 {
00020 cgiScript & script;
00021 bool CanEdit;
00022 bool IsSignedIn;
00023 bool Secured;
00024 Document_Obj document;
00025 public:
00026 document_list_functor(page & ipg,cgiScript & script, bool CanEdit, bool IsSignedIn)
00027 :base_functor(ipg),script(script),CanEdit(CanEdit),IsSignedIn(IsSignedIn),Secured(false)
00028 {;}
00029 virtual ~document_list_functor()
00030 {;}
00031
00032 virtual bool operator()( xmlNode & node )
00033 {
00034 bool bRet = false;
00035
00036 node_attr::iterator x = node.attr.find("secured");
00037 if( x!=node.attr.end() && x->second == "true") Secured = true;
00038
00039 paragraphMap & paras = pg.get_template().getParagraphs();
00040 ocString category, entries;
00041
00042 if( IsSignedIn == true || Secured == false )
00043 {
00044 x = node.attr.find("category");
00045 if( x!=node.attr.end() )
00046 {
00047 category = paras[x->second];
00048 }
00049 else
00050 {
00051
00052 script << "can't find document_list 'category' tag " << endl;
00053 }
00054 x = node.attr.find("entries");
00055 if( x!=node.attr.end() )
00056 {
00057 entries = paras[x->second];
00058
00059
00060 string clause = "Visible > 0";
00061
00062 if( document.get_data(clause, "Sequence, Category, Name" ) )
00063 {
00064 string lastCat;
00065 do {
00066 if ( lastCat != document.Category )
00067 {
00068 lastCat = document.Category;
00069 script << category.replace("$category$",lastCat);
00070 }
00071 ocString documentId;
00072 documentId.append(document.Id);
00073 editIcon( paras, node, documentId );
00074 script << entries
00075 .replaceAll("$id$", documentId)
00076 .replace("$location$",document.Filename)
00077 .replaceAll("$label$",document.Name)
00078 .replace("$description$",document.Description);
00079
00080 } while(document.next());
00081 }
00082 else
00083 {
00084 script << document.last_result();
00085 }
00086 }
00087 else
00088 {
00089 script << "can't find document_list 'entries' tag " << endl;
00090 }
00091 addIcon( paras, node );
00092 }
00093
00094 return bRet;
00095 }
00096
00097 void editIcon( paragraphMap & paras, xmlNode & node, string Id )
00098 {
00099 if( CanEdit )
00100 {
00101 ocString editLink;
00102 node_attr::iterator x = node.attr.find("editlink");
00103 if( x!=node.attr.end() )
00104 {
00105 editLink = paras[x->second];
00106 script << editLink
00107 .replaceAll("$id$", Id );
00108 }
00109 else
00110 {
00111 script << "can't find document_list 'editLink' tag " << endl;
00112 }
00113 }
00114 }
00115 void addIcon( paragraphMap & paras, xmlNode & node )
00116 {
00117 if( CanEdit )
00118 {
00119 ocString addLink;
00120 node_attr::iterator x = node.attr.find("addlink");
00121 if( x!=node.attr.end() )
00122 {
00123 addLink = paras[x->second];
00124 script << addLink;
00125 }
00126 else
00127 {
00128 script << "can't find document_list 'addlink' tag " << endl;
00129 }
00130 }
00131 }
00132
00133 };
00134
00135
00136 bool intraMain(page & pg ,cgiScript & script)
00137 {
00138 return true;
00139 }
00140
00141
00142 int main(int argc, char ** argv)
00143 {
00144 baseUrl = "intranet.meta";
00145
00146 cgiScript script("text/html",false);
00147 bool isSignedOn = check(script);
00148 script.closeHeader();
00149
00150 page pg(script);
00151
00152 writelog( "load page" );
00153 if( pg.load() )
00154 {
00155 writelog( "instance of page control" );
00156 page_control ctrl(pg);
00157 ctrl.addOp ( "servicelist", new servicelist_functor(pg,script,isSignedOn) );
00158 ctrl.addOp ( "userinterface", new form_functor(pg,script,isSignedOn) );
00159 ctrl.addOp ( "qrycontent", new qrystr_content_functor(pg,script) );
00160 ctrl.addOp ( "documentlist", new document_list_functor(pg,script,oLogin.SiteAdmin(), isSignedOn) );
00161 writelog( "page control emit" );
00162 ctrl.emit();
00163 }
00164 else
00165 {
00166 script << "<html><head><title>Page Unavailable</title></head>" << endl
00167 << "<body><h1>Sorry</h1>" << endl
00168 << "<p>The page you requested is not available</p></body></html>";
00169 }
00170 return 0;
00171 }
00172
00173
00174 #include "read_write_base.cpp"